john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

wc

# 2012-10-18 johnpfeiffer

import sys

CORRECTUSAGE = "python wc.py pathAndFilename"

arglength = len(sys.argv)
if arglength != 2:

    sys.exit(  "".join( ["Incorrect number of arguments, correct usage: " , CORRECTUSAGE ] ) )


wordcount = 0
f = open(sys.argv[1])
flines = f.readlines()
linecount = len(flines)

for l in flines:
    checkline()

print linecount, wordcount



def checkline():
    global l
    global wordcount
    w = l.split()
    wordcount += len(w)

  • « LdapSearchCLI
  • Webdav cadaver »

Published

Oct 19, 2012

Category

python

~48 words

Tags

  • python 180
  • wc 1