Last active
July 11, 2018 21:11
-
-
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
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
| # 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