string.count issue (simple)

Halfdan Holger Knudsen s011362 at bohr.gbar.dtu.dk
Fri Aug 29 09:21:41 EDT 2003


ok first off: Has the string.count function been replaced in python 2.2
(as compared to 1.5)?m And second:

I need this in relation to a stringsearch program
assuming a text file has been loaded into allLines and word contains the
string you're searching for I want to count all occurences of the search
string the following should do it (but doesn't - please disregard any
missing colons or such this has not been copy/pasted):

count = 0

for eachLine in allLines:
    if eachLine.find(word) > -1:
        count = count + eachLine.count(word, beg=0, end=len(eachLine)
        print eachLine
print count

what am I missing - it only outputs the nubmer of lines (as if the count
statement had been count = count + 1)

thanks
H





More information about the Python-list mailing list