Unicode string in exec

Jeff Epler jepler at unpythonic.net
Thu Jun 2 13:51:51 EDT 2005


First off, I just have to correct your terminology.  "exec" is a
statement, and doesn't require parentheses, so talking about "exec()"
invites confusion.

I'll answer your question in terms of eval(), which takes a string
representing a Python expression, interprets it, and returns the result.

In Python 2.3, the following works right:
    >>> eval(u"u'\u0190'")
    u'\u0190'
Here, the string passed to eval() contains the literal LATIN CAPITAL
LETTER OPEN E, and the expected unicode string is returned

The following behaves "surprisingly":
    >>> eval(u"'\u0190'")
    '\xc6\x90'
... you seem to get the UTF-8 encoding of the unicode.

This is related to PEP 263 (http://www.python.org/peps/pep-0263.html)
but the behavior of compile(), eval() and exec don't seem to be spelled
out.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050602/0df720cd/attachment.sig>


More information about the Python-list mailing list