[Python-ideas] Deprecate str.find

Mike Graham mikegraham at gmail.com
Sat Jul 16 19:39:34 CEST 2011


On Sat, Jul 16, 2011 at 11:26 AM, Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
> Unless an API is flat out broken, deprecation is almost always a bad idea.
> This API has been around for a very long time, so deprecating it will
> break lots of people's code for almost zero benefit:
> http://www.google.com/codesearch#search/&q=%5C.find%5C(%20lang:%5Epython$&type=cs
>
> Raymond

I agree that breaking people's code is a bad thing and have not
suggested removing str.find. This removal would require a transition
like that from Python 2.x to Python 3.x, a move that is not planned
and I personally do not ever expect.

I appreciate your linking this search, which does indeed does show
that str.find is in wide use. However, looking at the first give pages
of results, this use seems largely unfortunate—literally the majority
of the times str.find is used, I would have used "substring in s" or
"s.startswith(substring)". I also see code like "pos = s.find("  (");
if pos + len(" (...)") > self._maxWidth:" which makes me very
uncomfortable and which I would have to read in detail to figure out
what's happening confidently if I was the maintaining the code.

Thanks for the reply,
Mike



More information about the Python-ideas mailing list