We have code that invokes a variable number of context managers depending on runtime parameters:
from contextlib import nested, contextmanager
@contextmanag
It seems that you are supposed to use the with
statement with multiple context manager instances.
from https://pymotw.com/2/contextlib/:
In Python 2.7 and later, nested() is deprecated because the with statement supports nesting directly.
import contextlib
@contextlib.contextmanager
def make_context(name):
print 'entering:', name
yield name
print 'exiting :', name
with make_context('A') as A, make_context('B') as B, make_context('C') as C:
print 'inside with statement:', A, B, C