[Python-ideas] with statement: multiple context manager

Sturla Molden sturla at molden.no
Mon Mar 2 13:21:09 CET 2009


On 3/1/2009 9:57 PM, Christian Heimes wrote:

>   with a, b as x, d as y:

I'd like to add that parentheses improve readability here:

    with a, (b as x), (d as y):

I am worried the proposed syntax could be a source of confusion and 
errors. E.g. when looking at

    with a,b as c,d:

my eyes read

    with nested(a,b) as c,d:

when Python would read

    with a,(b as c),d:


It may actually be better to keep the current implementation with 
contextlib.nested.

If contextlib.nested is not well known (I only learned of its existence 
recently), maybe it should be better documented? Tutorial examples of 
the with statement should cover contextlib.nested as well.


Sturla Molden




More information about the Python-ideas mailing list