[Python-3000] Droping find/rfind?

Nick Coghlan ncoghlan at gmail.com
Wed Aug 23 13:43:12 CEST 2006

Guido van Rossum wrote:
> 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 be more interested in a patch that replaced standard library uses of
find()/rfind() with either "if sub in string" or partition()/rpartition(). 
Replacing usage of find() for slicing purposes is one of the big reasons the 
latter methods were added, after all.

I also like Josiah's idea of replacing find() with a search() method that 
returned an iterator of indices, so that you can do:

for idx in string.search(sub):
    # Process the indices (if any)

Then you have 5 substring searching mechanisms for different uses cases:

   sub in s          (simple containment test)
   s.index(sub)      (first index, exception if not found)
   s.search(sub)     (iterator of indices, empty if not found)
   s.partition(sep)  (split on first occurrence of substring)
   s.split(sep)      (split on all occurrences of substring)



Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-3000 mailing list