Skip to content

Commit 3022163

Browse files
committed
amended cat.py to address counter review
1 parent 3770801 commit 3022163

File tree

1 file changed

+8
-9
lines changed
  • implement-shell-tools/cat

1 file changed

+8
-9
lines changed

implement-shell-tools/cat/cat.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ def main():
1414

1515
args = parser.parse_args()
1616

17-
line_number = 1
18-
non_blank_line_number = 1
17+
counter = 1
1918

2019
for file_path in args.path:
2120
try:
@@ -27,14 +26,14 @@ def main():
2726
if i == len(lines) - 1 and line == "": # Skip the last empty line if it exists
2827
break
2928
prefix = ""
30-
if args.n:
31-
prefix = str(line_number).rjust(6) + " "
32-
elif args.b and line != "":
33-
prefix = str(non_blank_line_number).rjust(6) + " "
29+
if args.b:
30+
if line != "":
31+
prefix = str(counter).rjust(6) + " "
32+
counter += 1
33+
elif args.n:
34+
prefix = str(counter).rjust(6) + " "
35+
counter += 1
3436
print(prefix + line)
35-
line_number += 1
36-
if line != "":
37-
non_blank_line_number += 1
3837

3938
except FileNotFoundError:
4039
print(f"cat: {file_path}: No such file or directory")

0 commit comments

Comments
 (0)