[Python-Dev] Remove str.find in 3.0?

Ron Adam rrr at ronadam.com
Sun Aug 28 20:46:53 CEST 2005


Raymond Hettinger wrote:

> Looking at sample code transformations shows that the high-power
> mxTextTools and re approaches do not simplify code that currently uses
> s.find().  In contrast, the proposed partition() method is a joy to use
> and has no surprises.  The following code transformation shows
> unbeatable simplicity and clarity.

+1

This doesn't cause any backward compatible issues as well!

> --- From CGIHTTPServer.py ---------------
> 
> def run_cgi(self):
>     """Execute a CGI script."""
>     dir, rest = self.cgi_info
>     i = rest.rfind('?')
>     if i >= 0:
>         rest, query = rest[:i], rest[i+1:]
>     else:
>         query = ''
>     i = rest.find('/')
>     if i >= 0:
>         script, rest = rest[:i], rest[i:]
>     else:
>         script, rest = rest, ''
>     . . .
> 
> 
> def run_cgi(self):
>     """Execute a CGI script."""
>     dir, rest = self.cgi_info
>     rest, _, query = rest.rpartition('?')
>     script, _, rest = rest.partition('/')
>     . . .

+1

Much easier to read and understand!

Cheers,
    Ron





More information about the Python-Dev mailing list