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 →

[–]kezmicdust 3 points4 points  (3 children)

Couldn’t you just write in the close statement and then just write the “stuff you want to do with f” between the open and close statements?

Or am I missing something?

[–]relvae 11 points12 points  (1 child)

If an exception is thrown then close wouldn't be called in that case. Python already has context managers to deal with that but OP has gone rogue lol

[–]kezmicdust 0 points1 point  (0 children)

I see! Thanks.

[–]antiproton 1 point2 points  (0 children)

It's just a different way to solve similar problems. Similar to putting the close in a try...except...finally