English

Write a try .... except statement that attempts to open a file for reading and catches the exception thrown when the file does not exist.

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?
Chapter 7: Data File Handling - EXERCISE [Page 145]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 7 Data File Handling
EXERCISE | Q 3. | Page 145
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×