[Python-ideas] Nested with statements

Mathias Panzenböck grosser.meister.morti at gmx.net
Tue Apr 28 22:09:55 CEST 2009


Pascal Chambon wrote:
 >
 > I agree with the idea of auto-nesting "with", however in the case you
 > pointed out, the main problem was the early evaluation of context
 > managers ;
 > maybe a solution would be to delay the creation of context managers,
 > with something like a partial application (cf functools).
 >
 > Roughly, we'd need a "delayedNested" function, which takes zero-argument
 > callables as parameters, and calls/instanciates them inside itself.
 >
 > Then just call* delayedNested(partial(A,...arguments...), partial(B,
 > ...arguments...))*/ /to have what you want.
 >

It would be much shorter and more readable to manually nest the with statements.

	-panzi



More information about the Python-ideas mailing list