[Python-bugs-list] [ python-Feature Requests-444708 ] Optional argument for string.strip()
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 12 Apr 2002 19:43:55 -0700
Feature Requests item #444708, was opened at 2001-07-26 04:35
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=355470&aid=444708&group_id=5470
Category: Python Interpreter Core
Group: None
Status: Open
Resolution: Accepted
Priority: 5
Submitted By: Simon Brunning (brunns)
Assigned to: Walter Dörwald (doerwalter)
Summary: Optional argument for string.strip()
Initial Comment:
The .split method on strings splits at whitespace by
default, but takes an optional argument allowing
splitting by other strings. The .strip method (and its
siblings), on the other hand, always strip whitespace.
On more than one occasion I would have found it useful
if these methods also took an optional argument
allowing other strings to be stripped. For example, to
strip, say, asterisks from a string you could do:
>>>fred = '**word**word**'
>>>fred.strip('*')
word**word
If nothing else, this would meany that we have a good
answer when people ask about a equivalent to
Perl's 'chomp' function - string.rstrip(os.linesep).
----------------------------------------------------------------------
>Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2002-04-12 22:43
Message:
Logged In: YES
user_id=3066
(I'd say this is a good reason not to use separate trackers
for features, bugs, & patches -- they're too closely related
to keep them separate, and links between them too tedious
when written only in tracker comments!)
I've updated the documentation for these methods in
Doc/lib/libstdtypes.tex revision 1.87.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2002-04-12 21:02
Message:
Logged In: YES
user_id=6380
Oops, I saw your remark too late.
I've checked in my own version of this for regular
strings...
Feel free to check in your version of this for Unicode
strings, and the docs etc.
----------------------------------------------------------------------
Comment By: Walter Dörwald (doerwalter)
Date: 2002-04-09 11:07
Message:
Logged In: YES
user_id=89016
So what happens to patch http://www.python.org/sf/424606
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2002-04-09 10:31
Message:
Logged In: YES
user_id=6380
Reopened. A good use case is str(2**100).rstrip('L').
----------------------------------------------------------------------
Comment By: Simon Brunning (brunns)
Date: 2002-03-07 05:45
Message:
Logged In: YES
user_id=156912
Closing, since this has already been rejected by the BDFL.
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2002-03-07 04:24
Message:
Logged In: YES
user_id=6656
FYI, this has already been rejected once as patch #424606.
----------------------------------------------------------------------
Comment By: Simon Brunning (brunns)
Date: 2002-03-07 03:33
Message:
Logged In: YES
user_id=156912
string.replace doesn't do the same thing. With our
hypothetical .strip argument, we have:
>>>fred = '**word**word**'
>>>fred.strip('*')
word**word
Using replace, we have:
>>>fred = '**word**word**'
>>>fred.replace('*', '')
wordword
See the difference?
----------------------------------------------------------------------
Comment By: Sean 'Shaleh' Perry (shaleh)
Date: 2002-03-06 17:16
Message:
Logged In: YES
user_id=37132
why is string.replace() not sufficient?
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=355470&aid=444708&group_id=5470