[Python-ideas] Deprecate str.find

Devin Jeanpierre jeanpierreda at gmail.com
Fri Jul 15 19:13:06 CEST 2011


On Fri, Jul 15, 2011 at 12:38 PM, Guido van Rossum <guido at python.org> wrote:
> 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.

The last time I used file.readline was to pass to tokenize, which is
complicated immensely by the logic necessary to support both the
iterator protocol and the readline protocol. i.e. it has to check for
both StopIteration _and_ the empty string, which makes it harder to
use, forces it to contain more redundant information.
I'm not swayed by the suggestion that file.readline is beautiful at
all: it predates the iterator protocol and should have been subsumed
by it. Instead it's another inconsistency in Python that tools have to
deal with or ignore completely.

Strings don't even bother to be compatible with .find, if you pass in
an index that was returned by .find() you might just get the wrong
result. It's pretty much only ever useful in the if check, which is in
essence identical to the try-except, except it adds the ability to
forget to check and produce incorrect behaviour -- this is not a feature.

Devin



More information about the Python-ideas mailing list