Last active
July 8, 2016 15:40
-
-
Save beefy/5f2cd29c70b4081e6cc373e0ff2f2013 to your computer and use it in GitHub Desktop.
Reads a file with legacy encoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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