Entry
How can I strip unwanted characters out of my string? Octal 240 for instance.
Jun 5th, 2000 19:50
unknown unknown, Ken Seehof
>>> import string
>>> string.replace("s\240p\240a\240m","\240","")
'spam'
But I want to actually strip them out of my string:
Can't exactly do that. Strings are immutable. If you don't know what
I mean by immutable, find out (mutability is a key concept of python).
(Hint: if strings were not immutable, they could not be safely used as
keys in dictionaries.)
So you'll have to settle for:
>>> s = "s\240p\240a\240m"
>>> s = string.replace(s, "\240", "")
>>> print s
spam