New to Python.
Roy Smith
roy at panix.com
Wed Mar 17 22:22:41 EST 2004
In article <h84i501homhvjv6a4ohmf0o4svlakcqtoa at 4ax.com>,
droog <droog at orange.gov> wrote:
> I was looking for the simpliest way of doing it. This is what I tried
> to do.
>
> f = open('C:\Python23\Samples\Bob.txt', 'r')
> counter = 0
> while True:
> line = f.readline()
> if len(line) == 0:
> break
> if line.find('customer'):
> counter = counter + 1
> print 'Found it ' + str(counter)
I cut-and-pasted the above onto my machine (just changed the pathname to
/usr/share/dict/words). It finds every line in the file! The problem
appears to be that the find() method returns -1 when there's no match,
which tests as True. Other than that, the code seems pretty reasonable.
More information about the Python-list
mailing list