From f55b2ab24e7059553d94f008e2ee814466677acd Mon Sep 17 00:00:00 2001 From: Xiaohui Yu Date: Thu, 4 Oct 2018 12:17:13 -0400 Subject: [PATCH 1/4] set file path --- word_count.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/word_count.py b/word_count.py index af78f28..69e7c10 100644 --- a/word_count.py +++ b/word_count.py @@ -5,8 +5,8 @@ parser = argparse.ArgumentParser( description="" ) parser.add_argument( - "arg", - help="what does this do?", + "data_file", + help="oath to the file we want to read", ) #------------------------------------------------------------------------------- @@ -15,6 +15,9 @@ args = parser.parse_args( ) +print(args) +print(args.data_file) + #------------------------------------------------------------------------------- # our code for analyzing the data #------------------------------------------------------------------------------- From 47a8ce4ca5b598803453ee23fd763580fe37c5b5 Mon Sep 17 00:00:00 2001 From: Xiaohui Yu Date: Thu, 4 Oct 2018 12:28:22 -0400 Subject: [PATCH 2/4] oepn and read lines of file --- word_count.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/word_count.py b/word_count.py index 69e7c10..2cdd93e 100644 --- a/word_count.py +++ b/word_count.py @@ -15,8 +15,20 @@ args = parser.parse_args( ) -print(args) -print(args.data_file) +print("args = ", args) +print("args.data_file = ", args.data_file) + +fh = open(args.data_file) +print("the file handle is", fh) + +words=0 +lines=0 +chars=0 + +for line in fh: + print(line) + + #------------------------------------------------------------------------------- # our code for analyzing the data From 2d296e2597a69d1f969ec7d6a9b4b2ef4cee681e Mon Sep 17 00:00:00 2001 From: Xiaohui Yu Date: Thu, 4 Oct 2018 12:35:16 -0400 Subject: [PATCH 3/4] oepn and read lines of file --- word_count.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/word_count.py b/word_count.py index 2cdd93e..9d2e9f5 100644 --- a/word_count.py +++ b/word_count.py @@ -26,7 +26,23 @@ chars=0 for line in fh: - print(line) + lines+=1 +print(lines) + + + + + + + + + + + + + + + From 2d964dfd62a7c2724cd9cff727f9ccdf5014b68b Mon Sep 17 00:00:00 2001 From: Xiaohui Yu Date: Thu, 4 Oct 2018 12:37:34 -0400 Subject: [PATCH 4/4] We've got word count. --- word_count.py | 1 + 1 file changed, 1 insertion(+) diff --git a/word_count.py b/word_count.py index 9d2e9f5..ba2533c 100644 --- a/word_count.py +++ b/word_count.py @@ -27,6 +27,7 @@ for line in fh: lines+=1 + print(lines)