Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- wordcount.py
- by aaron@andcuriouser.com
- Crawls through every .txt file in the current directory and gives you a
- total word count for all the documents.
- Prerequisities:
- None
- Usage:
- python wordcount.py
- """
- import os
- file_list = os.listdir(".")
- textfiles = []
- wordcount = 0
- for f in file_list:
- if f[-3:] == "txt":
- textfiles.append(f)
- for f in textfiles:
- file = open(f)
- while True:
- line = file.readline()
- if not line:
- break
- wordcount += len(line.split(None))
- print
- print "Files:\t\t", len(textfiles)
- print "Wordcount:\t", wordcount
- print "Average:\t", (wordcount/len(textfiles)), "words/file"
- print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement