Skip to content

Instantly share code, notes, and snippets.

@MagneticMule
Created November 9, 2015 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MagneticMule/27dfd659710684d3ce2c to your computer and use it in GitHub Desktop.
Save MagneticMule/27dfd659710684d3ce2c to your computer and use it in GitHub Desktop.
def read_file(file_name):
"""reads a file in to memory,
first checking the user has access rights to the file"""
try:
fp = open(file_name, 'r')
except IOError as e:
if e.errno == errno.EACCES:
return False
raise
else:
with fp:
return fp.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment