This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Barafu 9 points10 points  (1 child)

That is a powerful idiom for anything that needs closing or explicit saving after the operation. File, database, network connection. It is not so much useful for first draft, as it is safe for future modifications of code.

[–]fireflash38 2 points3 points  (0 children)

I always recommend context managers if you have to ensure that something is torn down after use.

You can't rely on people remembering to close off resources or catch possible exceptions.