strip not working on strings?

marduk usenet at marduk.letterboxes.org
Sun Nov 13 16:30:54 EST 2005


On Sun, 2005-11-13 at 13:16 -0800, dan.j.weber at gmail.com wrote:
> I'm using Python 2.3.5 and when I type the following in the interactive
> prompt I see that strip() is not working as advertised:
> 
> >>>s = 'p p:p'
> >>>s.strip(' :')
> 'p p:p'
> 
> Is this just me or does it not work? I want to get rid of all ' ' and
> ':' in the string. I've checked the doc and from what I can tell this
> is what strip() is supposed to do. Thanks for any help.
> 

According to my docs it says "Return a copy of the string with the
leading and trailing characters removed."  There are no leading or
trailing spaces or colons in 'p p:p'.

What your probably looking for is the .replace() method.

-m




More information about the Python-list mailing list