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

Phillip J. Eby pje at telecommunity.com
Wed Aug 31 05:49:15 CEST 2005

At 01:05 AM 8/31/2005 +0200, Fredrik Lundh wrote:
>Ron Adam wrote:
> > For cases where single values are desired, attribues could work.
> >
> > Slicing:
> >        line = line.partition(';').head
> >        line = line.partition('#').head
> >
> > But it gets awkward as soon as you want more than one.
> >
> >        sep, port = host.partition(':').head, host.partition(':').sep
>unless you go for the piece approach
>     host, port = host.piece(":", 1, 2)
>(which, of course, is short for
>     host, port = host.piece(":").group(1, 2)
>and wait for Mr Eby to tell you that piece has nothing whatsoever
>to do with string splitting.

No, just to point out that you can make up whatever semantics you want, but 
the semantics you show above are *not* the same as what are shown at the 
page the person who posted about $PIECE cited, and on whose content I based 
my reply:


If you were following those semantics, then the code you presented above is 
buggy, as host.piece(':',1,2) would return the original string!

Of course, since I know nothing of MUMPS besides what's on that page, it's 
entirely possible I've misinterpreted that page in some hideously subtle 
way -- as I pointed out in my original post regarding $PIECE.  I like to 
remind myself and others of the possibility that I *could* be wrong, even 
when I'm *certain* I'm right, because it helps keep me from appearing any 
more arrogant than I already do, and it also helps to keep me from looking 
too stupid in those cases where I turn out to be wrong.  Perhaps you might 
find that approach useful as well.

In any case, to avoid confusion, you should probably specify the semantics 
of your piece() proposal in Python terms, so that those of us who don't 
know MUMPS have some possibility of grasping the inner mysteries of your 

More information about the Python-Dev mailing list