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 sys
33import os
44
5+ # TODO: decompose into functions to make it more modular and reusable
6+
57parser = argparse .ArgumentParser (
68 prog = "a simple version of wc. Takes in one or more files." ,
79 description = "ls command line tool which can accept -l -w -c cflags" )
4042
4143 line_count = len (lines )
4244 totals ["l" ] += line_count
43- output_str += f"\t { line_count } "
45+ output_str += f"{ line_count :8 } "
4446
4547 if (args .w ):
4648 word_count = 0
4749 for line in lines :
4850 # python string.split splits on any white space
4951 word_count += len (line .split ())
5052 totals ["w" ] += word_count
51- output_str += f"\t { word_count } "
53+ output_str += f"{ word_count :8 } "
5254
5355 if (args .c ):
5456 bytes = os .path .getsize (path )
5557 totals ["c" ] += bytes
56- output_str += f"\t { bytes } "
58+ output_str += f"{ bytes :8 } "
5759
5860 output_str += f" { path } "
5961 print (output_str )
6365 if val != 0 }
6466 total_str = ""
6567 for v in res .values ():
66- total_str += f"\t { v } "
68+ total_str += f"{ v :8 } "
6769
6870 total_str += " total"
6971 print (total_str )
You can’t perform that action at this time.
0 commit comments