constructing binary backslash-n

Steven Arnold stevena at
Thu Sep 30 05:59:09 CEST 2004

On Sep 29, 2004, at 11:47 PM, Steven Bethard wrote:

> 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')
> '\\r'
>>>> ('\\\\' + 'n').decode('string_escape')
> '\\n'
> (I just learned this today in an earlier thread...)

Yes!  Perfect.  I assume your backslashes got screwed up like my 
earlier message.  I think what you meant was:

 >>> ('<backslash><backslash>' + 'r').decode('string_escape')

THAT is exactly what I was looking for.  Thanks!


More information about the Python-list mailing list