Skip to content

Commit 3a7ef49

Browse files
committed
python cat refactoring
1 parent 3413558 commit 3a7ef49

File tree

3 files changed

+7
-30
lines changed

3 files changed

+7
-30
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:

individual-shell-tools/ls/script-01.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

individual-shell-tools/ls/script-02.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)