Amaury Forgeot d'Arc <amaur...@gmail.com> added the comment: This is a duplicate of issue4626.
Here, the content is correctly decoded with cp1252, then passed to compile(); but compile() works on the internal utf-8 representation, and tries to decode it again with cp1252! Yes, the error message is overwritten. If I remove the code that sets the "unknown encoding" exception, I get: >>> compile(open("c:/temp/t1252.py", encoding="cp1252").read(), "t1252.py", "exec") SyntaxError: 'charmap' codec can't decode byte 0x9d in position 35: character maps to <undefined> The 0x9d explains easily: >>> b"\x94".decode('cp1252').encode('utf8') b'\xe2\x80\x9d' ---------- nosy: +amaury.forgeotdarc superseder: -> compile() doesn't ignore the source encoding when a string is passed in _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue4742> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com