butterflyTee 0 Light Poster
import sys

def main():

usage = 'Usage: %s [options] <file name>\n' % sys.argv[0]
options =           'Options:\n'
options = options + '  -c, --chars    print the character counts\n'
options = options + '  -l, --lines    print the newline counts\n'
options = options + '  -w, --words    print the word counts\n'
usage = usage + options
 
countChars = 0
countWords = 0
countLines = 0

main()


and 


import sys

def main():

filename = "test.txt" 

try: 
    file = open(filename) 
except IOError, why: 
    print 'Unable to open file.\n', why 
    sys.exit(-1) 

charCount = lineCount = wordCount = 0 

for line in file.xreadlines(): 
    lineCount += 1 
    wordCount += len(line.split()) 
    charCount += len(line) 

print lineCount, wordCount, charCount

main()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.