Skip to content

Commit 68a9ce0

Browse files
committed
def a new method to read file to make main clean and organised
1 parent 33d638c commit 68a9ce0

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

  • implement-shell-tools/cat

implement-shell-tools/cat/cat.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import argparse
22
import sys
33

4+
def read_files(paths):
5+
lines = []
6+
for path in paths:
7+
try:
8+
with open(path, "r", encoding="utf-8") as f:
9+
lines.extend(f.read().splitlines())
10+
except OSError as e:
11+
print(f"Error reading {path}: {e}", file=sys.stderr)
12+
sys.exit(1)
13+
return lines
14+
415
def main():
516
parser = argparse.ArgumentParser(
617
prog="display-content-of-a-file",

0 commit comments

Comments
 (0)