[issue10187] exec encode unicode to utf-8 str automatically in GBK environment
Martin v. Löwis
report at bugs.python.org
Sun Oct 24 09:15:05 CEST 2010
Martin v. Löwis <martin at v.loewis.de> added the comment:
> oh,you mentioned the PEP 263
> but I already set a header like this,you can see the attached test.py
> #coding=GBK
You have that in test.py, but not in the string you are giving to exec.
This is really a separate source code.
So you could have written
exec '''#coding:GBK
print hi('%s')
''' % a
You didn't, hence the code you pass to exec has no declared source encoding.
> why exec choose to use utf-8 not GBK?
exec always choses UTF-8 when exec'ing Unicode strings. The source
encoding of the file that has the exec statement must be irrelevant:
the string being exec'ed may have been received from a different source
file.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10187>
_______________________________________
More information about the Python-bugs-list
mailing list