Guido van Rossum wrote:
I'd like to add the optional argument support for strip and friends to 2.2.2. It solves a real problem, and is useful for people going forward (in the same way as the not-really-bool() code).
Go ahead. Maybe Walter wants to help? (Walter: there's no obligation, and I understand if you prefer not to learn about CVS branches just yet. :-)
I have not problems with branches, but I guess that those that do backports regularily have scripts that simplify the job. 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" -- Walter Dörwald · LivingLogic AG, Bayreuth/Germany · www.livinglogic.de
=?iso-8859-1?Q?Walter_D=F6rwald?= writes:
your version: "oofoo".strip("foo") => "" my version: "oofoo".strip("foo") => "oo"
It sounds like yours is more like Perl's chomp(), with an option about what to chomp off. Not a bad idea, not sure I'd ever use more than: line = line.chomp('\n') -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> PythonLabs at Zope Corporation
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
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"
Aargh! I prefer my version -- it's more similar to the default usage (which boils down to something like s.strip(" \t\n\r\f")) and more practical (e.g. stripping trailing punctuation). --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (4)
-
Alex Martelli
-
Fred L. Drake, Jr.
-
Guido van Rossum
-
Walter Dörwald