def get_bom(fn, compression=None):
 boms = set((codecs.BOM_UTF16, codecs.BOM_UTF16_BE, codecs.BOM_UTF16_LE))
 with open(fn, mode='rb', compression=compression) as f:
  f.seek(0)
  bom = f.read(2)
  f.seek(0)
 if (bom in boms):
  return bom
 else:
  return ''

def get_bom ( fn , compression = None ) : boms = set ( ( codecs . BOM_UTF16 , codecs . BOM_UTF16_BE , codecs . BOM_UTF16_LE ) ) with open ( fn , mode = 'rb' , compression = compression ) as f : f . seek ( 0 ) bom = f . read ( 2 ) f . seek ( 0 ) if ( bom in boms ) : return bom else : return ''
get the byte order mark if it exists .