I was reading this question and it comes to my mind I needed it also, but in Python.
So I'm wondering if there is a way of doing that with the with
statement in Python.
Basically what I want is some kind of IDisposable (C#) analogy in Python. I know, for sure it will be a little different, I think something like:
class ForUseInWith(IDisposableLike):
#something here
pass
and use it like this:
with ForUseInWith() as disposable:
#something here
pass
Currently I'm figuring out how to do this studying the python reference and the PEP 343, if I manage to do a good solution and a clever example I will post here the answer. But in the way maybe you can help me.