On 4/6/2012 6:05 PM, Cameron Simpson wrote:
On 06Apr2012 16:57, Terry Reedy<[email protected]> wrote:
| On 4/6/2012 1:52 PM, Nicholas Cole wrote:
|>>>> bytes(s, 'utf-8').decode('unicode_escape')
|>
|> This seems very ugly (and slightly 'wrong'). Is there no way to do
|> this without using bytes? Have I missed something?
|
|>>> eval("'"+s+"'")
| 'Hello: this is a test'
https://xkcd.com/327/
I actually thought of that, but assumed that adding enclosing quotes
would be safe (or that the OP trusted the string). After sending, I
realized that if Nasty Hacker guessed that the string would be so
augmented, then it would not be safe. This or above with literal_eval is.
>>> ast.literal_eval("'{}'".format('\x3a'))
':'
---
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list