Re: Problem with the strip string method
- From: Steve Holden <steve@xxxxxxxxxxxxx>
- Date: Sun, 02 Mar 2008 12:45:50 -0500
Colin J. Williams wrote:
The Library Reference hasAdjust your expectations. The software is correct.
strip( [chars])
Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped:
>>> ' spacious '.strip()
'spacious'
>>> 'www.example.com'.strip('cmowz.')
'example'
Only the last two examples below behave as expected.
Is it intended that the full range of characters be handled?
Colin W.
[Dbg]>>> 'ab$%\n\rcd'.strip('%')
'ab$%\n\rcd'
[Dbg]>>> 'ab$%cd'.strip('$')
'ab$%\n\rcd'
[Dbg]>>> 'ab$%cd'.strip('$')
'ab$%cd'
[Dbg]>>> ' ab$%cd '.strip('$')
' ab$%cd '
[Dbg]>>> ' ab$%cd '.strip('%')
' ab$%cd '
[Dbg]>>> ' spacious '.strip()
'spacious'
[Dbg]>>> 'www.example.com'.strip('cmowz.')
'example'
I suspect what you need is the .replace() method.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
.
- Follow-Ups:
- Re: Problem with the strip string method
- From: castironpi
- Re: Problem with the strip string method
- References:
- Problem with the strip string method
- From: Colin J. Williams
- Problem with the strip string method
- Prev by Date: Re: Question on importing and function defs
- Next by Date: Re: Beautiful Code in Python?
- Previous by thread: Re: Problem with the strip string method
- Next by thread: Re: Problem with the strip string method
- Index(es):
Relevant Pages
|
Loading