[Tutor] counting in a file

reavey reavey@nep.net
Sun Nov 17 18:57:02 2002


Sirs:
I'm trying to count the number of times a word occurs in a file. 
I'm trying to do this using 
import sys,string
z = open("filename","r")
a = 0
while a<10:
	new = z.readline().strip()
	a = a+1

I'm using this method because readlines()
produces an unacceptable list as my lines are long.
Also, if I want to count the word "a" every word in the list with an "a"
is counted for example "at","and" etc.
I've tried to write the z.readline().strip() output to another file I
open, but I can only write to a file using the type string.
I like the way the strip function makes a multi element list.

The new in the above code works, however, I end up with the last line
that is converted to type(list).

If I try to increment the variable new, type(list) I get a type
mismatch.

Thanks in advance for any suggestions.

RE-v