Re: Problem with the strip string method



Colin J. Williams wrote:
The Library Reference has
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.

Adjust your expectations. The software is correct.

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/

.



Relevant Pages

  • Problem with the strip string method
    ... strip([chars]) ... The chars argument is a string specifying the set of characters to be removed. ...
    (comp.lang.python)
  • Re: unix filename restriction
    ... underscore _ and the dot. ... You could use other characters, ... never met a *human* defined path of more than 80 chars (most of the ... If you want to be very sure, limit your filename to the DOS limit of 8 ...
    (comp.os.linux.development.apps)
  • Re: Predefined Cell Character Length
    ... =LEFTreturns up to 10 characters. ... If 3 chars in a cell just those 3 will be returned. ... Gord Dibben MS Excel MVP ... cells in clumn A can only be 10 characters at the most, ...
    (microsoft.public.excel.worksheet.functions)
  • Re: 128 bit password
    ... Joe Richards Microsoft MVP Windows Server Directory Services ... Assumption would be that it would get truncated at 127/128 characters... ... then these are 16 bit chars. ...
    (microsoft.public.security)
  • Re: RfD: c-addr/len
    ... know that there is no practical value in using CHARS. ... I intend to go for 32-bit characters ... On SP-Forth, there is no command-line editing, only backspace. ... strings without having to know how they break into display characters; ...
    (comp.lang.forth)

Loading