Adding BOM (unicode signature) while saving file in python

Solution 1:

Write it directly at the beginning of the file:

file_new.write('\ufeff')

Solution 2:

It's better to use constants from 'codecs' module.

import codecs
f.write(codecs.BOM_UTF16_LE)