constructing binary backslash-n

Grant Edwards grante at
Thu Sep 30 05:52:44 CEST 2004

On 2004-09-30, Steven Arnold <stevena at> wrote:

> I want to be able to receive a letter like 'n', let's say as user 
> input, and generate the single byte escape value of backslash-n or 
> ASCII 10, as a string of length 1.  If the user provided the letter 
> 'r', I would return a string one character long, for which 
> ord(my_string) == 13.  This should be equivalent to the string 
> '<backslash>r'.

eval(r"'\%s'" % c)

where c is the single character string in question (e.g. "r" or
"n" or whatever).

Grant Edwards                   grante             Yow!  I love ROCK 'N
                                  at               ROLL! I memorized the
                                 all WORDS to "WIPE-OUT"

More information about the Python-list mailing list