more on unescaping escapes

Tim Wintle tim.wintle at teamrubber.com
Tue Feb 24 01:13:06 CET 2009


On Mon, 2009-02-23 at 17:00 -0700, bvdp wrote:
> Let's see if this makes sense:
> 
>  >>> a='c:\\Program Files\\test'
>  >>> a.decode('string-escape')
> 'c:\\Program Files\test'

Hint: try running

>>> print a

and see what's written - I think that the interpreter adds extra "\"
characters to escape things and make things more easy to read.

i.e. 

>>> a = "c:\\test\\t"
>>> a
'c:\\test\\t'
>>> print a
c:\test\t
>>> 

so when it displays strings in the interpreter it includes escape
characters, when it is printed though the output is straight to stdout
and isn't escaped.

Hope that helps,

Tim Wintle





More information about the Python-list mailing list