may have to manually write and skip the bom yourself in some scenarios if it is required or present--study the following examples for more bom-making instructionsopen('temp txt'' 'encoding='utf- -be'write('\ufeffspam\nspam\ ' open('spam txt''rb'read( '\xfe\xff\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \nopen('temp txt'' 'encoding='utf- 'read('spam\nspam\nopen('temp txt'' 'encoding='utf- -be'read('\ufeffspam\nspam\nthe more specific utf- encoding names work fine with bom-less filesthough "utf- requires one on input in order to determine byte orderopen('temp txt'' 'encoding='utf- -le'write('spam' open('temp txt''rb'read(ok if bom not present or expected ' \ \ \ \ open('temp txt'' 'encoding='utf- -le'read('spamopen('temp txt'' 'encoding='utf- 'read(unicodeerrorutf- stream does not start with bom experiment with these encodings yourself or see python' library manuals for more details on the bom unicode files in the preceding discussion applies to python ' string types and files you can achieve similar effects for unicode files in xbut the interface is different howeverif you replace str with unicode and open with codecs openthe result is essentially the same in xc:\codec:\python \python ' \xc \xe cprint aabec len( encode('latin- '' \xc \xe cs encode('utf- '' \xc \ \xc \xa cimport codecs codecs open('latindata'' 'encoding='latin- 'write(scodecs open('utfdata'' 'encoding='utf- 'write(sopen('latindata''rb'read(' \xc \xe copen('utfdata''rb'read(' \xc \ \xc \xa unicode and byte strings type manual calls files writes encode