Skip to content

Instantly share code, notes, and snippets.

@ndaifallah
Last active July 11, 2018 21:11
Show Gist options
  • Select an option

  • Save ndaifallah/1075201f03d50c163803c9ad56b922f5 to your computer and use it in GitHub Desktop.

Select an option

Save ndaifallah/1075201f03d50c163803c9ad56b922f5 to your computer and use it in GitHub Desktop.
Open any text file, with the basic encodings utf-8 and widnows-1252
# The solution for usual problems of opening files with specific encoding, french, englis,arabic ....
def openHoweverFile(filename):
f = None
try:
f = open(filename, 'r', encoding='utf-8')
except UnicodeDecodeError:
f = open(filename, 'r', encoding='windows-1252')
return f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment