Skip to content

Commit 7bff937

Browse files
committed
python cat refactoring
1 parent 3413558 commit 7bff937

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

implement-shell-tools/cat/my_cat.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
line_num = 1
2323

2424
for line in lines:
25-
if args.number_nonblank:
26-
if line.strip() != "":
27-
print(f"{line_num:6}\t{line}", end="")
28-
line_num += 1
29-
else:
30-
print(line, end="")
31-
elif args.number:
25+
should_number = False
26+
if args.number_nonblank and line.strip():
27+
should_number = True
28+
elif args.number and not args.number_nonblank:
29+
should_number = True
30+
31+
if should_number:
3232
print(f"{line_num:6}\t{line}", end="")
3333
line_num += 1
3434
else:

0 commit comments

Comments
 (0)