Skip to content

Instantly share code, notes, and snippets.

@beefy
Last active July 8, 2016 15:40
Show Gist options
  • Save beefy/5f2cd29c70b4081e6cc373e0ff2f2013 to your computer and use it in GitHub Desktop.
Save beefy/5f2cd29c70b4081e6cc373e0ff2f2013 to your computer and use it in GitHub Desktop.
Reads a file with legacy encoding
# taken from:
# http://stackoverflow.com/questions/22459020/python-decode-utf-16-file-with-bom
def decode_legacy(file_name):
encoded_text = open(file_name,'rb').read()
bom = codecs.BOM_UTF16_LE
assert encoded_text.startswith(bom)
encoded_text= encoded_text[len(bom):]
decoded_text= encoded_text.decode('utf-16le')
return decoded_text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment