Python - Context Managers
What will be the output of this code?
with open('test.txt', 'w') as f:
f.write('Hello')
print(f.closed)with open('test.txt', 'w') as f:
f.write('Hello')
print(f.closed)with block effectwith block, which automatically closes the file after the block ends.f.closed property after blockf is out of scope and not defined, so accessing f.closed raises a NameError.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions