PEP proposal: enhanced string functions

Oliver Fromme olli at secnetix.de
Wed Nov 14 08:14:09 EST 2001


Martin Franklin <martin.franklin at westgeo.com> wrote:
 > Matthew Dixon Cowles wrote:
 >> On 13 Nov 2001 12:54:47 -0800, Stephen Ferg <steve at ferg.org> wrote:
 >>>Title: Optional pad character for string justification functions
 >> 
 >> I like this.
 > 
 > Me too.

For the center() case, it might be useful to optionally
allow another argument, so you can have different padding
on the left and on the right.

Example:
>>> string.center(" Title ", 25, ">", "<")
'>>>>>>>>> Title <<<<<<<<<'


 >>>Title: Optional argument for string strip functions
 > [...]
 >> This bothers me a bit for the same reason that the split() method
 >> does. It strikes me as weird that without arguments, split() splits on
 >> all whitespace but that it will only take one character as an
 >> argument. I'd prefer to be able to pass a sequence to strip() and have
 >> any of those characters stripped.
 > 
 > how about adding new methods stripc(), rstripc(), lstripc(),  (or 
 > stripchar()) then maybe stripword() etc for what you want......

I'm not so convinced about that.  Instead of adding a
whole bunch of new functions, maybe better think about
using re.sub and re.split, which already do what you
want (and more).

Just my 0.02 Euro.

Regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"All that we see or seem is just a dream within a dream" (E. A. Poe)



More information about the Python-list mailing list