[Python-Dev] Fwd: Problem withthe API for str.rpartition()

Raymond Hettinger rhettinger at ewtllc.com
Tue Sep 5 20:32:46 CEST 2006


Jim Jewett wrote: 

>
> Another possibility is data (for head/tail) and unparsed (for rest).
>
>    S.partition(sep) -> (data, sep, unparsed)
>    S.rpartition(sep) -> (unparsed, sep, data)


This communicates very little about the ordering of the return tuple.  
Beware of overly general terms like "data" that provide no hints about 
the semantics of the method.

The one good part that the terms are consistent between partition and 
rpartition so that the invariant can be stated:

    assert sep not in datum

I recommend we just leave the existing head/tail wording and add an 
example which will make the meaning instantly clear:
   'www.python.org'.rpartition('.')    -->   ('www.python', '.', 'org')

Also, remember that this discussion is being held in abstract.  An 
actual user of rpartition() is already thinking in terms of parsing from 
the end of the string.

Another thought is that strings don't really have a left and right.  
They have a beginning and end.  The left/right or top/bottom distinction 
is culture specific.


Raymond


BTW, if someone chops your ankles, does it matter which way you're 
facing to decide whether it was your feet or your head that had been 
cut-off?





More information about the Python-Dev mailing list