I ran into this on Python 3 and found this question (and solution). When opening a file, Python 3 supports the encoding keyword to automatically handle the encoding.
Without it, the BOM is included in the read result:
>>> f = open('file', mode='r') >>> f.read() '\ufefftest'
Giving the correct encoding, the BOM is omitted in the result:
>>> f = open('file', mode='r', encoding='utf-8-sig') >>> f.read() 'test'
Just my 2 cents.
~ Answered on 2018-03-07 11:25:12