[Python-bugs-list] [ python-Feature Requests-444708 ] Optional argument for string.strip()
noreply@sourceforge.net
noreply@sourceforge.net
Tue, 09 Apr 2002 07:31:25 -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: Later
Priority: 5
Submitted By: Simon Brunning (brunns)
Assigned to: Nobody/Anonymous (nobody)
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: 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