Closed svisser closed 9 years ago
Oh man I was looking for a function like that (specifically, a defer close
statement like in Go/other languages), and forgot about with
. Thanks, I'll change it to use with
soon.
I saw the title of this issue and knew who was the culprit.
Well, I have indeed filed this issue in multiple projects as it's a common thing (both in the codebase as well as in setup.py
). For example, installation using setup.py
enables many things but it's also weird that it requires arbitrary code execution to install the package. So it makes sense to treat it as any other code (closing file handles etc).
Various files are being opened and manually closed by
.close()
but this means, if an exception were to occur, the file isn't closed. It's better to use the with statement here as this ensures the files are indeed closed, even when exceptions occur.