Created
February 29, 2016 02:50
-
-
Save davismj/5ceb7f307f4038ba3264 to your computer and use it in GitHub Desktop.
get_text_from_file
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
def get_text_from_file(file_path): | |
value = None | |
try: | |
with open(file_path, mode='r') as file: | |
value = file.read() | |
except UnicodeDecodeError: | |
try: | |
with open(file_path, mode='rb') as file: | |
value = file.read() | |
except: | |
raise ValueError('Cannot read binary file {0}'.format(file_path)) | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment