[Python-ideas] Deprecate str.find

Raymond Hettinger raymond.hettinger at gmail.com
Sun Jul 17 00:05:23 CEST 2011


On Jul 16, 2011, at 2:04 PM, Mike Graham wrote:
> 
> Did you catch Nick's suggestion to enhance str.index to have the same
> basic API as dict.get/getattr/etc.?

Sorry, but I thought idea that was way off base.
Things like dict.get and getattr are about returning values,
so it is possible to provide a meaningful default.
In the case of string.find, there is no meaningful
default position in the string.  So, a default would simply 
be a way to turn the -1 value into some other object 
which you would still need to test.

We don't need to make the API worse by expanding it
just for the sake of change.  The str.find() method isn't
broken or useless.  If you want people to change the
way they write code, it would be better to do it through
education (blog posts, pylint, etc) rather than by
breaking a venerable API.


Raymond




More information about the Python-ideas mailing list