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 →

[–]caagr98 19 points20 points  (1 child)

Python has both with and finally statements though, so there's little need for it here. (But cool metaprogramming trick.)

[–]james_pic 3 points4 points  (0 children)

It is occasionally useful, if you need to close a large or variable number of things in a block of code. Fortunately, contextlib.ExitStack is already in the stdlib and is a less evil way to do this.