contextlib.nested()

Peter Otten __peter__ at web.de
Fri Nov 7 04:33:51 EST 2008


brasse wrote:

> with nested(Foo('a'), Foo('b', True)) as (a, b):
>     print a.tag
>     print b.tag

If been watching this thread for a while, and I think that your problems
will go away if you write actual nested with-blocks:

with Foo("a") as a:
    with Foo("b") as b:
        print a.tag
        print b.tag

Why look for a complex solution if there is a simple one?

Peter



More information about the Python-list mailing list