eryksun added the comment:

You're passing an already decoded string, so the BOM is treated as text. 
Instead open the file in binary mode, i.e. open("bom3.py", "rb"). This way the 
BOM will be detected when decoding the source bytes. Here's an example that 
passes the source as a bytes object:

    >>> source = b'\xef\xbb\xbf#coding: utf-8\nprint("spam")'
    >>> code = compile(source, '<string>', 'exec')
    >>> exec(code)
    spam

Or you could also decode the file contents without the BOM via open("bom3.py", 
encoding="utf-8-sig").

----------
nosy: +eryksun
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25051>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to