File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import argparse
2+ import os
23
34parser = argparse .ArgumentParser (prog = "wc" ,usage = "implement a simple wc in python" )
45parser .add_argument ("path" ,nargs = "+" )
56args = parser .parse_args ()
67
7- print (args .path )
8+ # print(args.path)
89paths = args .path
9- for path in paths :
10- with open (path ,"r" ) as f :
10+ words_count = 0
11+ total_lines = 0
12+ total_words = 0
13+ total_bytes = 0
14+
15+ for file in paths :
16+ with open (file ,"r" ) as f :
17+ bytes_count = os .path .getsize (file )
1118 lines = f .readlines ()
12- print (len (lines ) , path )
19+ lines_count = len (lines )
20+ for line in lines :
21+ words_count += len (line .split ())
22+ total_lines += lines_count
23+ total_bytes += bytes_count
24+ total_words += words_count
25+ print (lines_count ,words_count , bytes_count , file )
26+ words_count = 0
27+
28+ print (total_lines ,total_words ,total_bytes ,"total" )
You can’t perform that action at this time.
0 commit comments