[Python-ideas] [offlist] Re: Deprecate str.find

Raymond Hettinger raymond.hettinger at gmail.com
Sat Jul 16 22:37:50 CEST 2011


On Jul 16, 2011, at 12:26 PM, Mike Graham wrote:

> Reviewing five pages of results, over 2/3 of the uses of str.find
> could be replaced by str.__contains__.

I think the first hit was from BeautifulSoup which predates
the introduction of __contains__ and still runs on both
old and new versions of Python.

It may be hard to believe, but in the old days (not really so
long ago), we didn't have __contains__ or startswith() 
and yet Python became popular anyway ;-) 

> Using sub in s instead of
> s.find(sub) != -1 is *already* the advice in the official Python
> documentation,

I know about that advice.  I believe I'm the one who added it ;-)
(as well as many other tips in the code modernization PEP).


Raymond



More information about the Python-ideas mailing list