constructing binary backslash-n

Steven Bethard steven.bethard at gmail.com
Thu Sep 30 05:47:14 CEST 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