[Tutor] Escape characters in strings
Glen Wheeler
wheelege@hotmail.com
Sun, 6 Jan 2002 15:56:58 +1100
Hi,
I was writing an internet script and when parsing text I came upon this
very problem. Nothing I tried would stop python from considering \xxx to be
anything other than one character...the way I did it in the end was to
redesign the way I parsed the strings and 'ignore' the \xxx parts.
This isn't helpful for you, since you obviously can't ignore them. I am
just posting here to show that your not the only one who has encountered
this problem before...
Hmmm, upon a bit of fiddling....
for i in s:
if '\\' in repr(i):
j = ''
j = repr(i)[1:-1]
n.append(j)
else:
n.append(i)
Sorta works :)
Glen
> [...]
>
> Doesn't work, that was the first thing I tried. For some reason Python's
not
> finding the '\' because it thinks '\300' is a single character rather than
> four.
>
> Even 'print x' will hide the \ in this case.
>