let' make some files with boms to see how this works in practice when you save text file in windows notepadyou can specify its encoding type in drop-down list-simple ascii textutf- or littleor big-endian utf- if two-line text file named spam txt is saved in notepad as the encoding type ansifor instanceit' written as simple ascii text without bom when this file is read in binary mode in pythonwe can see the actual bytes stored in the file when it' read as textpython performs endof-line translation by defaultwe can also decode it as explicit utf- text since ascii is subset of this scheme (and utf- is python ' default encoding) :\codec:\python \python file saved in notepad import sys sys getdefaultencoding('utf- open('spam txt''rb'read(ascii (utf- text file 'spam\ \nspam\ \nopen('spam txt'' 'read(text mode translates line end 'spam\nspam\nopen('spam txt'' 'encoding='utf- 'read('spam\nspam\nif this file is instead saved as utf- in notepadit is prepended with -byte utf- bom sequenceand we need to give more specific encoding name ("utf- -sig"to force python to skip the markeropen('spam txt''rb'read(utf- with -byte bom '\xef\xbb\xbfspam\ \nspam\ \nopen('spam txt'' 'read(' >>?spam\nspam\nopen('spam txt'' 'encoding='utf- 'read('\ufeffspam\nspam\nopen('spam txt'' 'encoding='utf- -sig'read('spam\nspam\nif the file is stored as unicode big endian in notepadwe get utf- -format data in the filewith -byte ( -bitcharacters prepended with -byte bom sequence--the encoding name "utf- in python skips the bom because it is implied (since all utf- files have bom)and "utf- -behandles the big-endian format but does not skip the bom (the second of the following fails to print on older pythons)open('spam txt''rb'read( '\xfe\xff\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \nopen('spam txt'' 'read('\xfey\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \nopen('spam txt'' 'encoding='utf- 'read('spam\nspam\nopen('spam txt'' 'encoding='utf- -be'read('\ufeffspam\nspam\nnotepad' "unicode,by the wayis utf- little endian (whichof courseis one of very many kinds of unicode encoding! unicode and byte strings