Skip to content

Commit 3a816e4

Browse files
committed
clean the code
1 parent e0be462 commit 3a816e4

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

  • implement-shell-tools/ls

implement-shell-tools/ls/ls.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,23 @@
77
)
88

99
parser.add_argument("path", nargs="?", help="The file to process", default=".")
10-
parser.add_argument("-1", "--one_per_line",action="store_true", help="one file per line")
10+
parser.add_argument(
11+
"-1", "--one_per_line", action="store_true", help="one file per line"
12+
)
1113
parser.add_argument("-a", action="store_true", help="Show hidden files")
1214

1315

1416
args = parser.parse_args()
1517

16-
path = Path(args.path) # path is an object represent a location on disk
17-
18-
# else:
19-
# for item in path.iterdir(): # iterdir is a method reads directory contents
20-
# if args.a:
21-
# print(item.name)
22-
# else:
23-
# if not item.name.startswith("."):
24-
# print(item.name) # each item is a Path object
25-
items =[]
18+
path = Path(args.path)
19+
20+
items = []
2621
for item in sorted(path.iterdir()):
2722
if args.a or not item.name.startswith("."):
2823
items.append(item.name)
2924

30-
if(args.one_per_line):
25+
if args.one_per_line:
3126
for name in items:
3227
print(name)
3328
else:
34-
print(" ".join(items))
29+
print(" ".join(items))

0 commit comments

Comments
 (0)