Files
troupe-standup/wizard-work/spark/word-counter.py
T

15 lines
422 B
Python
Executable File

#!/usr/bin/env python3
"""Simple word counter - counts words in a text file."""
import sys
def count_words(filepath):
"""Count words in a file and return the total."""
with open(filepath, 'r') as f:
text = f.read()
return len(text.split())
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: word-counter.py <filepath>")
sys.exit(1)
print(count_words(sys.argv[1]))