I have a question about closing a file in a python withoperator
import os
with os.popen('ls') as f:
print f.read()
raise IOError
print f
print f
As you can see in the code snippet above, I open the file using the operator with, I know that the file will be closed automatically after exiting the block with, but if some kind of error occurs inside the block, does it happen with the file f, will it be closed?
source
share