Skip to content

Instantly share code, notes, and snippets.

@RaminNietzsche
Created February 25, 2016 06:14
Show Gist options
  • Save RaminNietzsche/f899a1fcabffcb285431 to your computer and use it in GitHub Desktop.
Save RaminNietzsche/f899a1fcabffcb285431 to your computer and use it in GitHub Desktop.
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