I have the following code:
with open("a.txt") as f:
data = f.read()
# operation on data
This will close the file a.txt
if there is any Error on my operations on data. I wanted to know, what if the file a.txt
doesn't exist.
Should my code be:
try:
with open("a.txt") as f:
data = f.read()
# operation on data
except IOError:
print "No such File"