Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type

Antoon Pardon apardon at forel.vub.ac.be
Fri Aug 26 04:22:33 EDT 2005


Op 2005-08-25, Bryan Olson schreef <fakeaddress at nowhere.org>:
> Steve Holden asked:
> > Do you just go round looking for trouble?
>
> In the course of programming, yes, absolutly.
>
> > As far as position reporting goes, it seems pretty clear that find()
> > will always report positive index values. In a five-character string
> > then -1 and 4 are effectively equivalent.
> >
> > What on earth makes you call this a bug?
>
> What you just said, versus what the doc says.
>
> > And what are you proposing that
> > find() should return if the substring isn't found at all? please don't
> > suggest it should raise an exception, as index() exists to provide that
> > functionality.
>
> There are a number of good options. A legal index is not one of
> them.

IMO, with find a number of "features" of python come together.
that create an awkward situation.

1) 0 is a false value, but indexes start at 0 so you can't
   return 0 to indicate nothing was found.

2) -1 is returned, which is both a true value and a legal
   index.


It probably is too late now, but I always felt, find should
have returned None when the substring isn't found.

-- 
Antoon Pardon



More information about the Python-list mailing list