[Python-ideas] Deprecate str.find

Masklinn masklinn at masklinn.net
Sat Jul 16 22:21:51 CEST 2011


On 2011-07-16, at 21:52 , Terry Reedy wrote:
> On 7/16/2011 2:46 PM, Terry Reedy wrote:
>> On 7/15/2011 6:50 PM, Cameron Simpson wrote:
>>> On 15Jul2011 12:12, Mike
>>> Graham<mikegraham at gmail.com> wrote:
>>> age etc.
>>> 
>>> str.find does not have a failure mode, it has string found and string
>>> not found.
>> 
>> Not finding == failure to find == failure to match an implied re.
> Indeed, negative values such as -1 are standard error/failure return codes for functions that normally return nonnegative ints and that written in statically typed languages without catchable exceptions
… or type systems worth using. And that's for those which are 0-indexed of course, especially for finding sub-sequences.

And interestingly, the function corresponding to `str.find` in libc returns `NULL` in case of failure, not −1 (its return value is a pointer to the first occurrence of the needle in the haysack).


More information about the Python-ideas mailing list