Skip to content

Instantly share code, notes, and snippets.

@axiaoxin
Created December 31, 2013 03:41
Show Gist options
  • Save axiaoxin/8192254 to your computer and use it in GitHub Desktop.
Save axiaoxin/8192254 to your computer and use it in GitHub Desktop.
def has_bom(fn):
with open(fn, 'rb') as f:
sample = f.read(4)
return sample[:3] == b'\xef\xbb\xbf' or \
sample.startswith(codecs.BOM_UTF16_LE) or \
sample.startswith(codecs.BOM_UTF16_BE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment