Translating escaped characters

Henrik S. Hansen hsh at freecode.dk
Mon Nov 1 17:33:23 EST 2004


How do you best go about translating characters like '\\n' to '\n'?
This is for a configuration file parser, where the "backslash
convention" is supported.

The naive approach -- re.sub('\\\\(.)', '\\\1', s) -- doesn't work, of
course.  The best I've come up with so far is a special case for every
character to be translated.  There must be an easier way?

-- 
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