alixander / PyScribe

DEPCRECATED/UNMAINTAINED - A Python library to make debugging with print statements simpler and more effective.
MIT License
375 stars 22 forks source link

Use with statement to ensure file handles are closed #4

Closed svisser closed 9 years ago

svisser commented 9 years ago

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.

alixander commented 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.

kragniz commented 9 years ago

I saw the title of this issue and knew who was the culprit.

svisser commented 9 years ago

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).

alixander commented 9 years ago

https://github.com/alixander/PyScribe/pull/7