Advertisements
Advertisements
Question
Write a try .... except statement that attempts to open a file for reading and catches the exception thrown when the file does not exist.
Code Writing
Advertisements
Solution
try:
file = open("data.txt", "r")
except FileNotFoundError:
print("File does not exist.")shaalaa.com
Is there an error in this question or solution?
