New to Python.
Roy Smith
roy at panix.com
Wed Mar 17 22:02:47 EST 2004
In article <sg3i50l1utn3drvqaggrm2rqf7n2erbu8h at 4ax.com>,
droog <droog at orange.gov> wrote:
> Hello!
>
> I have just started learning python and encountered a problem.
> All I wanted to do, was to open a text file search and count the
> number of occurances of a single word and print that count.
> Thanks for help.
>
Well, I'll point you in the right direction.
To open a file, use the "open" function. You can loop through the lines
with something like "for line in file:". Depending on exactly how you
define "word", you might want to look at the split() string method, or
maybe some regular expression matching with the "re" module.
There, that should be enough to get you started with your homework
assignment :-)
More information about the Python-list
mailing list