Using repr() with escape sequences

nummertolv nummertolv at gmail.com
Thu Feb 23 11:49:37 EST 2006


I think I might have misused the terms "escape character" and/or
"escape sequence" or been unclear in some other way because I seem to
have confused you. In any case you don't seem to be addressing my
problem.

I know that the \t in the example path is interpreted as the tab
character (that was part of the point of the example) and what the
strings are representing is irrelevant. And yes, the way the strings
are displayed is part of the issue.

So let me try to be clearer by boiling the problem down to this:

- Consider a string variable containing backslashes.
- One or more of the backslashes are followed by one of the letters
a,b,f,v or a number.

myString = "bar\foo\12foobar"

How do I print this string so that the output is as below?

bar\foo\12foobar

typing 'print myString' prints the following:

bar
oo
foobar

and typing print repr(myString) prints this:

'bar\x0coo\nfoobar'


Hope this makes it clearer. I guess there is a simple solution to this
but I have not been able to find it. Thanks.

/H




More information about the Python-list mailing list