Skip to content

Commit 92929e0

Browse files
committed
move total before helper function process_file otherwise error is thrown and get rid of code no longer in use
1 parent 5158913 commit 92929e0

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@
1414

1515
args = 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

2419
def 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

5448
for 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

0 commit comments

Comments
 (0)