[Python-ideas] allow tuples in a with statement?

Tim Golden mail at timgolden.me.uk
Tue Jan 13 21:43:32 CET 2009


Sturla Molden wrote:
> Sometimes multiple arguments in a with statement would be convinient.
> 
> with open('in.txt','rt'), \
>      open('out.txt','wt'),\
>      open('err.txt','wt') \
>      as fstdin, fstdout, fstderr:
> 
> But today this has to be written as:
> 
> with open('in.txt','rt') as fstdin:
>    with open('out.txt','wt') as fstdout:
>       with open('err.txt','wt') as fstderr:
> 
> with the effect of causing multiple redundant levels of intendation.

contextlib.nested ?

TJG



More information about the Python-ideas mailing list