r/Python • • Feb 28 '13

What's the one code snippet/python trick/etc did you wish you knew when you learned python?

I think this is cool:

import this

259 Upvotes

307 comments sorted by

View all comments

Show parent comments

3

u/[deleted] Feb 28 '13

Yes. It ensures that the file is closed/the mutex is released, even if there's an exception while the inner code is being executed.

It's a context manager, if you want to look up more details.

2

u/[deleted] Feb 28 '13 edited Feb 19 '25

This was removed because of API shenanigans, selling user content for AI training, and forthcoming paywalled subreddits.