Skip to content

Commit 87d8179

Browse files
committed
wc formatting matches real formatting exactly.
1 parent 575f0bf commit 87d8179

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import sys
33
import os
44

5+
# TODO: decompose into functions to make it more modular and reusable
6+
57
parser = argparse.ArgumentParser(
68
prog="a simple version of wc. Takes in one or more files.",
79
description="ls command line tool which can accept -l -w -c cflags")
@@ -40,20 +42,20 @@
4042

4143
line_count = len(lines)
4244
totals["l"] += line_count
43-
output_str += f"\t{line_count}"
45+
output_str += f"{line_count:8}"
4446

4547
if (args.w):
4648
word_count = 0
4749
for line in lines:
4850
# python string.split splits on any white space
4951
word_count += len(line.split())
5052
totals["w"] += word_count
51-
output_str += f"\t{word_count}"
53+
output_str += f"{word_count:8}"
5254

5355
if (args.c):
5456
bytes = os.path.getsize(path)
5557
totals["c"] += bytes
56-
output_str += f"\t{bytes}"
58+
output_str += f"{bytes:8}"
5759

5860
output_str += f" {path}"
5961
print(output_str)
@@ -63,7 +65,7 @@
6365
if val != 0}
6466
total_str = ""
6567
for v in res.values():
66-
total_str += f"\t{v}"
68+
total_str += f"{v:8}"
6769

6870
total_str += " total"
6971
print(total_str)

0 commit comments

Comments
 (0)