Another Wart! string.find() [ was: namespace issue? ]
Michael Powe
michael+gnus at trollope.org
Fri Jun 22 10:20:28 EDT 2001
>>>>> "Steven" == Steven D Majewski <sdm7g at Virginia.EDU> writes:
Steven> On 21 Jun 2001, Michael Powe wrote:
>> So now the question is, 'why'? Am I misusing the string.find()
>> function? Okay, string.find() returns -1 when the string is not
>> found, which would seem to be what I expected, a false result.
>> Maybe python doesn't treat -1 as false? Well, I'll try being
>> explicit and testing for -1 return. I probably have just
>> confused myself hopelessly.
Steven> You got it!
Steven> 0, 0.0, "", [], (), and None, as well as classes that
Steven> return 0 from methods __nonzero__ or __len__ are false.
Steven> everything else (unless I missed one ;-) is true.
Steven> -1 is true.
Steven> But find can't return 0 because it is a valid offset
Steven> that signifies the beginning of a string, so it returns
Steven> -1.
Yeah, I shoulda thunk. I would have realized this. ;-(
mp
More information about the Python-list
mailing list