Resource management, class edition
Implement __enter__ and __exit__ to build custom with blocks. Return False from __exit__ to propagate exceptions.
Pro tip: contextlib.contextmanager lets you write them with yield — less boilerplate, same power.
Output
Press Run to execute your code.