In this code i am checking for an error when trying to open the file but how can i also check for an error when reading the file?
try:
with open("file.txt") as f:
contents = f.read()
except FileNotFoundError:
print("File Not Found")
In this code i am checking for an error when trying to open the file but how can i also check for an error when reading the file?
try:
with open("file.txt") as f:
contents = f.read()
except FileNotFoundError:
print("File Not Found")
You can have multiple except statements. So just add another one after your current except for the error that you want to deal with this time.