constructing binary backslash-n

Steven Bethard steven.bethard at
Thu Sep 30 05:47:14 CEST 2004

Steven Arnold <stevena <at>> 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')
>>> ('\\' + 'n').decode('string_escape')

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


More information about the Python-list mailing list