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

skip@pobox.com skip at pobox.com
Wed Aug 31 15:02:40 CEST 2005

    >> You can do both: make partition() return a sequence with attributes,
    >> similar to os.stat().  However, I would call the attributes "before",
    >> "sep", and "after".

    Terry> One could see that as a special-case back-compatibility kludge
    Terry> that maybe should disappear in 3.0.  

Back compatibility with what?  Since partition doesn't exist now there is
nothing to be backward compatible with is there?

I'm -1 on the notion of generating groups or attributes.  In other cases
(regular expressions, stat() results) there are good reasons to provide
them.  The results of a regular expression match are variable, depending on
how many groups the user defines in his pattern.  In the case of stat()
there is no reason other than historic for the results to be returned in any
particular order, so having named attributes makes the results easier to
work with.  The partition method has neither.  It always returns a fixed
tuple of three elements whose order is clearly based on the physical
relationship of the three pieces of the string that have been partitioned.

I think Raymond's original formulation is the correct one.  Always return a
three-element tuple of strings, nothing more.  Use '_' or 'dummy' if there
is some element you're not interested in.


More information about the Python-Dev mailing list