Translating escaped characters

Henrik S. Hansen hsh at freecode.dk
Tue Nov 2 02:12:08 EST 2004


Steven Bethard <steven.bethard at gmail.com> 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'

Precisely, thank you.

-- 
Henrik S. Hansen     http://freecode.dk/~hsh/
Computer science (software engineering) student
Free Software Foundation member #1702 (http://member.fsf.org)



More information about the Python-list mailing list