Skip to content

Instantly share code, notes, and snippets.

@tyr0chen
Created February 20, 2015 13:23
Show Gist options
  • Save tyr0chen/ff3bd08210813ed07457 to your computer and use it in GitHub Desktop.
Save tyr0chen/ff3bd08210813ed07457 to your computer and use it in GitHub Desktop.
wc for python
import sys
totol_lines=totol_words=totol_characters=0
for loop in sys.argv[1:]:
pfile=open(loop,'rU')
lines=words=characters=0
for eve_line in pfile:
lines+=1
words+=len(eve_line.split())
characters+=len(eve_line)
print "%d\t%d\t%d\t%s"%(lines,words,characters,loop)
totol_lines+=lines
totol_words+=words
totol_characters+=characters
if len(sys.argv)>2:
print "%d\t%d\t%d\t%s"%(totol_lines,totol_words,totol_characters,'totol')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment