constructing binary backslash-n

Grant Edwards grante at visi.com
Wed Sep 29 23:52:44 EDT 2004


On 2004-09-30, Steven Arnold <stevena at neosynapse.net> 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
                               visi.com            all WORDS to "WIPE-OUT"
                                                   in1965!!



More information about the Python-list mailing list