[Python-Dev] Fwd: Problem withthe API for str.rpartition() (original) (raw)
Raymond Hettinger rhettinger at ewtllc.com
Tue Sep 5 19:10:47 CEST 2006
- Previous message: [Python-Dev] Fwd: Problem withthe API for str.rpartition()
- Next message: [Python-Dev] Fwd: Problem withthe API for str.rpartition()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
This change looks wrong: PyDocSTRVAR(rpartition_doc,_ _-"S.rpartition(sep) -> (head, sep, tail)\n_ _+"S.rpartition(sep) -> (tail, sep, head)\n_ It looks like the code itself does the right thing, but I wasn't quite confident of that. It is correct. There may be some confusion in terminology. Head and tail do not mean left-side or right-side. Instead, they refer to the "small part chopped-off" and "the rest that is still choppable". Think of head and tail in the sense of car and cdr.
A post-condition invariant for both str.partition() and str.rpartition() is:
assert sep not in head
For non-looping cases, users will likely to use different variable names when they unpack the tuple:
left, middle, right = s.rpartition(p)
But when they perform multiple partitions, the "tail" or "rest" terminology is more appropriate for the part of the string that may still contain separators.
Raymond
- Previous message: [Python-Dev] Fwd: Problem withthe API for str.rpartition()
- Next message: [Python-Dev] Fwd: Problem withthe API for str.rpartition()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]