File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66parser .add_argument ("-w" ,
77 "--words" ,
8- dest = "words_count " ,
8+ dest = "show_words " ,
99 action = "store_true" ,
1010 help = "print word count" )
1111
1212parser .add_argument ("-l" ,
1313 "--lines" ,
14- dest = "lines_count " ,
14+ dest = "show_lines " ,
1515 action = "store_true" ,
1616 help = "print line count" )
1717
1818parser .add_argument ("-c" ,
1919 "--bytes" ,
20- dest = "byte_count " ,
20+ dest = "show_bytes " ,
2121 action = "store_true" ,
2222 help = "print byte count" )
2323
2424parser .add_argument ("path" )
2525
2626args = parser .parse_args ()
27+
28+ if not args .show_lines and not args .show_words and not args .show_bytes :
29+ args .show_lines = True
30+ args .show_words = True
31+ args .show_bytes = True
32+
33+ with open (args .path , "rb" ) as file :
34+ content = file .read ()
35+
36+ word_count = str (len (content .split ()))
37+ line_count = str (content .count (b"\n " ))
38+ byte_count = str (len (content ))
39+
40+ outputs = []
41+
42+ if args .show_lines :
43+ outputs .append (line_count )
44+
45+ if args .show_words :
46+ outputs .append (word_count )
47+
48+ if args .show_bytes :
49+ outputs .append (byte_count )
50+
51+ outputs .append (args .path )
52+
53+ output = "\t " .join (outputs )
54+ print (output )
You can’t perform that action at this time.
0 commit comments