with block that has a file open for writing.
try:
with open("data.txt", "w") as f:
f.write("12")
x = 1 / 0
except ZeroDivisionError:
print("caught", f.closed, open("data.txt").read())
What does the program print?Log in to join the discussion.
Loading…