New to Python.
droog at orange.gov
Thu Mar 18 04:28:22 CET 2004
Could you please show me an alternative and better way of doing it?
On Wed, 17 Mar 2004 22:22:41 -0500, Roy Smith <roy at panix.com> wrote:
>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:
>> 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