What is the best way in python to handle reading a file that may potentially not exist?
Currently I have the following:
try:
with open(filename, "r") as f:
return f.read()
except IOError:
return False
Is this the best way to do it or is this wrong on any level at all?
I guess my biggest concerns are:
- Catching the exception only to return false
- Maybe i am missing a 'Python' way of silently missing the error for a missing file