Created
February 25, 2016 06:14
-
-
Save RaminNietzsche/f899a1fcabffcb285431 to your computer and use it in GitHub Desktop.
This file contains 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
coding = codec_detector(file) | |
with io.open(file, encoding=coding) as word_list: | |
print(word_list.readlines()) | |
def codec_detector(file): | |
codec = '' | |
with open(file) as word_list: | |
BOM = word_list.read(2) | |
if BOM == b'\xff\xfe' or BOM == b'\xff\xef': | |
codec="utf-16" | |
else: | |
codec="utf-8" | |
return codec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment