Chain dynamic iterable of context managers to a single with statement
问题 I have a bunch of context managers that I want to chain. On the first glance, contextlib.nested looked like a fitting solution. However, this method is flagged as deprecated in the documentation which also states that the latest with statement allows this directly: Deprecated since version 2.7: The with-statement now supports this functionality directly (without the confusing error prone quirks). However I could not get Python 3.4.3 to use a dynamic iterable of context managers: class Foo():