Skip to content

Commit 558abe6

Browse files
committed
com ruff format for rest files
1 parent 0027636 commit 558abe6

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

implement-shell-tools/cat/cat.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import argparse
22

33
parser = argparse.ArgumentParser(
4-
prog = "cat-command",
5-
description = "cat shell command in python "
4+
prog="cat-command", description="cat shell command in python "
65
)
76

8-
parser.add_argument("-n", action="store_true", help="Display all lines numbers")
9-
parser.add_argument("-b", action="store_true", help="Display numbers non-empty lines")
7+
parser.add_argument("-n", action="store_true", help="Display all lines numbers")
8+
parser.add_argument("-b", action="store_true", help="Display numbers non-empty lines")
109
parser.add_argument("path", nargs="+", help="The file to search")
1110

1211
args = parser.parse_args()
@@ -19,13 +18,13 @@
1918
if args.n:
2019
for line in content:
2120
print(f"{number}\t{line.strip()}")
22-
number +=1
21+
number += 1
2322
elif args.b:
2423
for line in content:
25-
if line.strip() !="":
24+
if line.strip() != "":
2625
print(f"{number}\t{line.strip()}")
27-
number +=1
28-
else:
26+
number += 1
27+
else:
2928
print("")
3029
else:
31-
print("".join(content))
30+
print("".join(content))

implement-shell-tools/wc/wc.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import argparse
22

33
parser = argparse.ArgumentParser(
4-
prog = "wc-count words, lines, characters",
5-
description = "wc shell command on python"
4+
prog="wc-count words, lines, characters", description="wc shell command on python"
65
)
76

87
parser.add_argument("-l", action="store_true", help="Count lines")
@@ -15,49 +14,42 @@
1514

1615
count_total_lines = 0
1716
count_total_words = 0
18-
count_total_bytes = 0
17+
count_total_bytes = 0
1918

2019
for file_path in args.path:
2120
with open(file_path, "r") as file:
2221
content = file.read()
2322

2423
count_lines = content.count("\n")
2524
count_words = len(content.split())
26-
count_bytes=len(content.encode("utf-8"))
25+
count_bytes = len(content.encode("utf-8"))
2726

28-
count_total_lines += count_lines
27+
count_total_lines += count_lines
2928
count_total_words += count_words
30-
count_total_bytes += count_bytes
29+
count_total_bytes += count_bytes
3130

3231
if not (args.l or args.w or args.c):
33-
print (count_lines, count_words, count_bytes, file_path)
32+
print(count_lines, count_words, count_bytes, file_path)
3433
else:
3534
line = ""
3635
if args.l:
3736
line += f"{count_lines} "
38-
if args.w:
37+
if args.w:
3938
line += f"{count_words} "
40-
if args.c:
39+
if args.c:
4140
line += f"{count_bytes} "
4241
line += f"{file_path}"
4342
print(line)
4443
if len(args.path) > 1:
4544
if not (args.l or args.w or args.c):
46-
print (count_total_lines, count_total_words, count_total_bytes, " total")
45+
print(count_total_lines, count_total_words, count_total_bytes, " total")
4746
else:
4847
line = ""
4948
if args.l:
5049
line += f"{count_total_lines} "
51-
if args.w:
50+
if args.w:
5251
line += f"{count_total_words} "
53-
if args.c:
52+
if args.c:
5453
line += f"{count_total_bytes} "
5554
line += " total"
5655
print(line)
57-
58-
59-
60-
61-
62-
63-

0 commit comments

Comments
 (0)