Question 8
Back to Exercise
What is the output of the following Python program?
import os, tempfile
os.chdir(tempfile.mkdtemp())
try:
open("missing.txt")
except FileNotFoundError as e:
print(type(e).__name__, isinstance(e, OSError), e.filename)
- A FileNotFoundError False missing.txt
- B FileNotFoundError True missing.txt Correct
- C OSError True missing.txt
- D IOError True None
Correct Answer: Option B
FileNotFoundError is an OSError, and the exception records the file name.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!