Created
February 20, 2015 13:23
-
-
Save tyr0chen/ff3bd08210813ed07457 to your computer and use it in GitHub Desktop.
wc for python
This file contains hidden or 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
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