Confirmation that is not interesting.
I was worried whether the context manager's termination process would be called properly when I returned in the block of the with statement.
In conclusion, it's okay.
withreturn.py
class Some(object):
def add(self, x, y):
return x + y
def close(self):
print "Closed"
from contextlib import closing
def foo(x):
with closing(Some()) as some:
return some.add(x, 10)
print foo(16)
# Closed
#=> 26
The termination process is called in this way.
Recommended Posts