[Python-Dev] (no subject)

Alex Martelli aleax@aleax.it
Thu, 18 Apr 2002 17:24:04 +0200


On Thursday 18 April 2002 05:06 pm, Walter Dörwald wrote:
	...
> What's still missing is the version for unicode. Note that my patch
> http://www.python.org/sf/424606 works a little different: Here the
> argument is a complete word that should be stripped, not a collection
> of characters, i.e.
> your version: "oofoo".strip("foo") => ""
> my version: "oofoo".strip("foo") => "oo"

It seems to me that Guido's version is easier to teach, and more useful.

Easier to teach, because one can present this as the argument's "default 
value" being string.whitespace; more useful because I more often have strings 
to clean up that may end with arbitrary sequences of "junk" characters I want 
to remove, rather than with a potential specific "junk" word (and the latter
case may be easier to handle with an .endswith test).  Admittedly the 
specific use case which Guido recently mentioned (cleaning up, if present, 
the trailing 'L' from a number's repr) is handled just as well in either way, 
since it's only one character.  But say e.g. I receive datagrams that may or 
may not end with trailing \r , \n, or \r\n -- .rstrip("\r\n") in Guido's 
version immediately solves my problem.  I can't think of a similarly generic 
use-case for yours (perhaps a failure of imagination on my part).


Alex