File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414
1515args = parser .parse_args ()
1616
17-
18- total_lines = 0
19- total_words = 0
20- total_characters = 0
21- file_count = 0
22-
17+ total = {'lines' : 0 , 'words' : 0 , 'characters' : 0 , 'files' : 0 }
2318
2419def counter (item ):
2520 lines = len (item .strip ().split ("\n " ))
@@ -28,7 +23,7 @@ def counter(item):
2823 return {"lines" : lines , "words" : words , "characters" : characters }
2924
3025
31- def process_file (file_path ):
26+ def process_file (file_path , total ):
3227 with open (file_path , "r" ) as f :
3328 content = f .read ()
3429
@@ -48,17 +43,16 @@ def process_file(file_path):
4843 total ['characters' ] += stats ['characters' ]
4944 total ['files' ] += 1
5045
51- total = {'lines' : 0 , 'words' : 0 , 'characters' : 0 , 'files' : 0 }
5246
5347
5448for path in args .paths :
5549 if os .path .isfile (path ):
56- process_file (path )
50+ process_file (path , total )
5751 elif os .path .isdir (path ):
5852 for file in os .listdir (path ):
5953 file_path = os .path .join (path , file )
6054 if os .path .isfile (file_path ):
61- process_file (file_path )
55+ process_file (file_path , total )
6256
6357
6458
You can’t perform that action at this time.
0 commit comments