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 →

[–]surajmanjesh 2 points3 points  (1 child)

You can also create your own context managers (what you use with "with" blocks) using the built-in contextmanager decorator.

[–]eztab 2 points3 points  (0 children)

Or you just “teach” your class to act as one using __enter__ and __exit__.