[Python-ideas] Deprecate str.find

Mike Graham mikegraham at gmail.com
Fri Jul 15 18:47:31 CEST 2011


On Fri, Jul 15, 2011 at 12:38 PM, Guido van Rossum <guido at python.org> wrote:
> On Fri, Jul 15, 2011 at 9:12 AM, Mike Graham <mikegraham at gmail.com> wrote:
>> It isn't necessarily an error if the substring is not in the string
>> (though it sometimes is), but it is an exceptional case. Python uses
>> exceptions pretty liberally most places -- it isn't necessarily an
>> error if an iterator is exhausted or if float("4.2 bad user input") is
>> called or if BdbQuit was raised. In these cases, an exception can be
>> perfectly expected to indicate that what happened is different from
>> the information used in a return value.
>
> This smells a bit like uncalled-for religion. Remember that readline()
> returns an empty string at the end of the file instead of raising an
> exception, and IMO that makes it the better API.
>
> --
> --Guido van Rossum (python.org/~guido)
>

Thanks for this prompt, considerate reply (and the other).

I really didn't mean to present an "always use exceptions" dogma here,
so much as to claim "Having the programmer use a try/except block
isn't a problem," and to say that the fact an exception was raised
doesn't necessarily indicate that something went wrong. StopIteration
is a strong example that exceptions can often be very expected and
normal.


Mike



More information about the Python-ideas mailing list