[Python-3000] Droping find/rfind? (original) (raw)

Georg Brandl g.brandl at gmx.net
Wed Aug 23 08:45:00 CEST 2006


Tim Peters wrote:

[Guido van Rossum]

At today's sprint, one of the volunteers completed a patch to rip out find() and rfind(), replacing all calls with index()/rindex(). But now I'm getting cold feet -- is this really a good idea? (It's been listed in PEP 3100 for a long time, but I haven't thought about it much, really.)

What do people think? I'd rather toss index/rindex myself, although I understand that [r]find's -1 return value for "not found" can trip up newbies. Like I care ;-)

Perhaps a search() method, like Josiah proposed, makes sense.

If you decide to toss [r]find anyway, I'd rather see "not found" be spelled with an exception more specific than ValueError (who knows what all "except ValueError:" is going to catch? /Just/ that the substring wasn't found? Ya, that's something to bet your life on ;-)).

Seriously, this is something I have thought of from time to time: an exceptions' "source", so that you could say

try: x = int(some expression) except ValueError from int: do something

Obviously, it's too much work to add such a thing though.

Georg



More information about the Python-3000 mailing list