constructing binary backslash-n

Steven Arnold stevena at neosynapse.net
Wed Sep 29 23:59:09 EDT 2004


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

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

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')
'<backslash>r'

THAT is exactly what I was looking for.  Thanks!

steve




More information about the Python-list mailing list