5 ms·
The equivalent code with out the context manager is actually this: f = open('foo.txt') try: contents = f.read() finally: f.close() So yes, ext
by codefisher 12y ago
The equivalent code with out the context manager is actually this:
f = open('foo.txt')
try:
contents = f.read()
finally:
f.close()
So yes, extra reason to prefer the context manager.