Skip to content

Instantly share code, notes, and snippets.

@lmergner
Last active December 17, 2015 15:29
Show Gist options
  • Save lmergner/5632363 to your computer and use it in GitHub Desktop.
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.
#!/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