Skip to content

Commit c6723d0

Browse files
Boshra MahmoudiBoshra Mahmoudi
authored andcommitted
implent cat by python
1 parent ebca147 commit c6723d0

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

  • implement-shell-tools/cat

‎implement-shell-tools/cat/cat.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import argparse
2+
3+
4+
parser = argparse.ArgumentParser(
5+
prog="cat implemnet by Python"
6+
)
7+
8+
parser.add_argument("-n", action="store_true")
9+
parser.add_argument("-b", action="store_true")
10+
parser.add_argument("files", nargs="+")
11+
12+
args = parser.parse_args()
13+
14+
line_number = 1
15+
16+
for filename in args.files:
17+
18+
with open(filename) as file:
19+
for line in file:
20+
line = line.rstrip("\n")
21+
22+
if args.b and line == "":
23+
print()
24+
continue
25+
26+
if args.n or args.b:
27+
print(f"{line_number} {line}")
28+
line_number += 1
29+
else:
30+
print(line)

0 commit comments

Comments
 (0)