[Python-Dev] Proof of the pudding: str.partition()

Fredrik Lundh fredrik at pythonware.com
Tue Aug 30 21:15:19 CEST 2005


Raymond Hettinger wrote:

> Overall, I found that partition() usefully encapsulated commonly
> occurring low-level programming patterns.  In most cases, it completely
> eliminated the need for slicing and indices.  In several cases, code was
> simplified dramatically; in some, the simplification was minor; and in a
> few cases, the complexity was about the same.  No cases were made worse.

it is, however, a bit worrying that you end up ignoring one or more
of the values in about 50% of your examples...

> !         rest, _, query = rest.rpartition('?')
> !         script, _, rest = rest.partition('/')
> !     _, sep, port = host.partition(':')
> !             head, sep, _ = path.rpartition('/')
> !                 line, _, _ = line.partition(';')  # strip 
> chunk-extensions
> !             host, _, port = host.rpartition(':')
> !         head, _, tail = name.partition('.')
> !             head, _, tail = tail.partition('.')
> !         pname, found, _ = pname.rpartition('.')
> !         head, _, tail = name.partition('.')
> !             filename, _, arg = arg.rpartition(':')
> !             line, _, _ = line.partition('#')
> !             protocol, _, condition = meth.partition('_')
> !         filename, _, _ = filename.partition(chr(0))

this is also a bit worrying

> !         head, found, tail = seq.find('-')

but that's more a problem with the test suite.

</F> 





More information about the Python-Dev mailing list