New to Python.
droog
droog at orange.gov
Wed Mar 17 22:28:22 EST 2004
Thanks Roy!
Could you please show me an alternative and better way of doing it?
tia
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:
>> 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