Suppose we have an object, which is intended to be used with with
:
with somefunction() as f:
...
f.somemethod()
Now I want to use it within class, to make object available full lifetime of class instance.
In constructor I would write
class MyClass:
def __init__(self):
self.f = somefunction().__enter__()
Where should I call __exit__()
then?