Last active
December 17, 2015 15:29
-
-
Save lmergner/5632363 to your computer and use it in GitHub Desktop.
A small command line utility taking one argument--a text file--counts the words and prints the number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
__doc__ = "A small command line utility taking one argument--a text file--counts the words and prints the number." | |
import os, sys | |
if len(sys.argv) == 2: | |
with open(os.path.abspath(sys.argv[1])) as f: | |
text = f.read() | |
words = text.split() | |
count = len(words) | |
print("File has %s words." % count) | |
else: | |
print("One filename is required. ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment