RFC PEP candidate: q'<delim>'quoted<delim> ?
Bengt Richter
bokr at oz.net
Mon Mar 11 01:43:42 EST 2002
On 11 Mar 2002 03:58:38 GMT, bokr at oz.net (Bengt Richter) wrote:
>On Mon, 11 Mar 2002 16:31:45 +1300, Greg Ewing <greg at cosc.canterbury.ac.nz> wrote:
>
>>Bengt Richter wrote:
>>>
>>> Would someone explain this:
>>>
>>> >>> eval("list(r'\x07')")
>>> ['\x07']
>>> >>> list(r'\x07')
>>> ['\\', 'x', '0', '7']
>>
>>The string literal you're passing to eval is
>>non-raw, so the \x07 gets interpreted before
>>eval even sees it. Try this instead:
>>
>> >>> eval(r"list(r'\x07')")
>>
>Aaugh, touché & d'oh. That's embarrassing ;-/
>
Especially since the original motivation was:
+---
|So how would '\x07' (single character) be represented if it were part of pasted text?
|
|I guess I ought to try eval("r'\x07'") and see what happens ;-)
+---
I.e., I was _intending_ to get \x07 interpreted, to simulate pasting a single control
character into a raw string. In another post I just did it directly:
+---
| >>> '^G','\x07',r'^G'
| ('\x07', '\x07', '\x07')
|
|... where I typed Ctrl-G binary data into the source where the screen rendered ^G.
+---
I just fooled myself looking at all those list results ;-/
Regards,
Bengt Richter
More information about the Python-list
mailing list