[Python-Dev] partition() (was: Remove str.find in 3.0?)
Nick Coghlan
ncoghlan at gmail.com
Tue Aug 30 14:42:20 CEST 2005
Pierre Barbier de Reuille wrote:
> What I'm talking about is consistency. In most cases in Python, or at
> least AFAIU, error testing is avoided and exception launching is
> preferred mainly for efficiency reasons. So my question remains: why
> prefer for that specific method returning an "error" value (i.e. an
> empty separator) against an exception ?
Because, in many cases, there is more to it than just the separator not being
found.
Given a non-empty some_str and some_sep:
head, sep, tail = some_str.partition(some_sep)
There are actually five possible results:
head and not sep and not tail (the separator was not found)
head and sep and not tail (the separator is at the end)
head and sep and tail (the separator is somewhere in the middle)
not head and sep and tail (the separator is at the start)
not head and sep and not tail (the separator is the whole string)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.blogspot.com
More information about the Python-Dev
mailing list