We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 37c7132 commit 5d1476bCopy full SHA for 5d1476b
1 file changed
implement-shell-tools/wc/wc.py
@@ -0,0 +1,22 @@
1
+import argparse
2
+
3
+# Setup argument parser
4
+parser = argparse.ArgumentParser(
5
+ prog="wc",
6
+ description="Count lines, words, and characters"
7
+)
8
+parser.add_argument("paths", nargs='+', help="Files to count")
9
10
+args = parser.parse_args()
11
12
+for path in args.paths:
13
+ # Read the file
14
+ with open(path, "r") as f:
15
+ content = f.read()
16
17
+ # Count lines, words, characters
18
+ lines = len(content.rstrip('\n').split('\n'))
19
+ words = len(content.split())
20
+ chars = len(content)
21
22
+ print(f"{lines:8}{words:8}{chars:8} {path}")
0 commit comments