Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
steve at holdenweb.com
Sat Aug 27 04:16:23 CEST 2005
Torsten Bronger wrote:
> "Terry Reedy" <tjreedy at udel.edu> writes:
>>"Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message
>>news:7xmzn41ofc.fsf at ruckus.brouhaha.com...
>>>"Terry Reedy" <tjreedy at udel.edu> writes:
>>>>Str.find is redundant with the Pythonic exception-raising
>>>>str.index and I think it should be removed in Py3.
>>>I like having it available so you don't have to clutter your code
>>>with try/except if the substring isn't there. But it should not
>>>return a valid integer index.
>>The try/except pattern is a pretty basic part of Python's design.
>>One could say the same about clutter for *every* function or
>>method that raises an exception on invalid input. Should more or
>>even all be duplicated? Why just this one?
> Granted, try/except can be used for deliberate case discrimination
> (which may even happen in the standard library in many places),
> however, it is only the second most elegant method -- the most
> elegant being "if". Where "if" does the job, it should be prefered
> in my opinion.
Of course. But onc you (sensibly) decide to use an "if" then there
really isn't much difference between -1, None, () and sys.maxint as
a sentinel value, is there?
Which is what I've been trying to say all along.
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list