File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22import os
33
44parser = argparse .ArgumentParser (prog = "wc" ,usage = "implement a simple wc in python" )
5+ parser .add_argument ("-l" ,action = "store_true" ,help = "count of lines" )
6+ parser .add_argument ("-w" ,action = "store_true" ,help = "count of words" )
7+ parser .add_argument ("-c" ,action = "store_true" ,help = "count of bytes" )
58parser .add_argument ("path" ,nargs = "+" )
69args = parser .parse_args ()
710
8- # print(args.path )
11+ print (args )
912paths = args .path
1013words_count = 0
1114total_lines = 0
2124 words_count += len (line .split ())
2225 total_lines += lines_count
2326 total_bytes += bytes_count
24- total_words += words_count
25- print (f"{ lines_count :<5} { words_count :<5} { bytes_count :<5} { file :<20} " )
27+ total_words += words_count
28+ if not (args .l or args .w or args .c ):
29+ args .l = True
30+ args .w = True
31+ args .c = True
32+ print ((f"{ lines_count :<5} " if args .l else "" )+
33+ (f"{ words_count :<5} " if args .w else "" )+
34+ (f"{ bytes_count :<5} " if args .c else "" )+
35+ f"{ file :<20} " )
2636 words_count = 0
2737
2838print (f"{ total_lines :<5} { total_words :<5} { total_bytes :<5} total" )
You can’t perform that action at this time.
0 commit comments