[Tutor] Please comment on this code...WORD FREQUENCY COUNTER

wesley chun wescpy at gmail.com
Mon Oct 23 23:21:49 CEST 2006

> I have written a program which calculates teh frequency of each word that
> appears in a file. I would like to have your feedback.
> This program only handles .txt files. I want it to handle word documents
> also. How to accomplish this ..???


you have made a good start.  one area of improvement you can make is
that your current code scans a file twice.  see if you can do it using
a single pass.

for doing it with Word, you can just use the same algorithm you have
developed above.  all you need to do is to use the Win32 COM client
libraries in the Python Extensions for Windows to open up a Word
document and pull out the text. there are many places to find out how
to open a Word document from Python, so i won't discuss it here.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca

More information about the Tutor mailing list