constructing binary backslash-n

Steven Bethard steven.bethard at gmail.com
Wed Sep 29 23:47:14 EDT 2004


Steven Arnold <stevena <at> neosynapse.net> writes:

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

Does this do what you're looking for:

>>> ('\\' + 'r').decode('string_escape')
'\r'
>>> ('\\' + 'n').decode('string_escape')
'\n'

(I just learned this today in an earlier thread...)

Steve




More information about the Python-list mailing list