Is it possible to ensure the __exit__() method is called even if there is an exception in __enter__()?
__exit__()
__enter__()
>>> class TstCont
No. If there is the chance that an exception could occur in __enter__() then you will need to catch it yourself and call a helper function that contains the cleanup code.