Skip to content

Commit 1ea4d3e

Browse files
committed
correctly print error message
1 parent 0e5e2ee commit 1ea4d3e

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,12 @@
1919
totals = {"l": 0, "w": 0, "c": 0}
2020

2121
for path in args.paths:
22-
try:
23-
if (os.path.isdir(path)):
24-
print(f"wc: {path}: read: Is a directory")
25-
except:
26-
print(f"wc: {path} open: No such file or directory", file=sys.stderr)
27-
file_count += 1
28-
continue
29-
30-
if (os.path.isfile(path)):
22+
if (not os.path.exists(path)):
23+
print(f"wc: {path}: open: No such file or directory", file=sys.stderr)
24+
elif (os.path.isdir(path)):
25+
print(f"wc: {path}: read: Is a directory")
26+
elif (os.path.isfile(path)):
3127
output_str = ""
32-
3328
with open(path, "r", encoding="utf-8") as file:
3429
lines = file.readlines()
3530

0 commit comments

Comments
 (0)