[Python-Dev] string.find() again (was Re: timsort for jython)

Aahz aahz@pythoncraft.com
Mon, 5 Aug 2002 12:38:35 -0400

On Mon, Aug 05, 2002, Guido van Rossum wrote:
>>> Um, you meant "is >= 0".  The find() method doesn't return a bool, it
>>> returns the first index where the string is found, and -1 if it is not
>>> found.
>> Which only goes to prove that the people who've been whining about that
>> characteristic of find() were right all along.  ;-)
> So what would you like it to return?  True/False, with no possibility
> of finding where the substring starts?  That defeats a common use
> case.

Well, of course it can't be changed, but if Tim of all people made that
mistake, I think it's a good indicator that something's wrong.  I believe
the suggestion has been made to add an exists() method or something
similar; it's probably better to have that in the core under some
standard name instead of each person who needs it implementing the
one-liner under different names.
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/