[Tutor] counting in a file
Thomi Richards
thomi@thomi.imail.net.nz
Sun Nov 17 20:21:01 2002
> I'm using this method because readlines()
> produces an unacceptable list as my lines are long.
I'm pretty sure you could do this: (you are trying to count the number
of _words_ ina file, right?
infile = open('infile.txt')
Nlines = 0
for line in infile.read():
Nlines+= len(string.strip(line))
print 'there are %d words in this file) % (Nlines)
i haven't tried this out, but thats roughly how I would do it. then
again, I'm still learning python, So there is probably a _much_ simpler
way to do this :-)
--
Lord, what fools these mortals be!
-- midsummer nights dream.
Thomi Richards,
thomi@imail.net.nz