Translating escaped characters

Steven Bethard steven.bethard at gmail.com
Mon Nov 1 17:59:48 EST 2004


Henrik S. Hansen <hsh <at> freecode.dk> writes:

> 
> How do you best go about translating characters like '\\n' to '\n'?

Is this what you're looking for?

>>> '\\n'.decode('string_escape')
'\n'
>>> '\n'.encode('string_escape')
'\\n'

There's some info about it here:

http://docs.python.org/lib/node127.html

and searching Google Groups shows up a few things too:

http://groups.google.com/groups?q=escape+sequences&
meta=group%3Dcomp.lang.python.*

(Sorry, the URL wrapped.)

Steve




More information about the Python-list mailing list