[Python-ideas] with statement: multiple context manager
Terry Reedy
tjreedy at udel.edu
Sun Mar 1 22:45:07 CET 2009
Calvin Spealman wrote:
> On Sun, Mar 1, 2009 at 4:01 PM, Gregory P. Smith <greg at krypto.org> wrote:
>> Alternatively if closer conformity with for loop syntax is desirable
>> consider this:
>> with lock, open(infile), open(outfile) as lock, fin, fout:
>> fout.fwrite(fin.read())
>
> +1
>
> We don't have multi-assignment statements in favor of the unpacking
> concept, and I think it carries over here. Also, as mentioned, this
> goes along with the lack of any multi-for statement. The `x as y` part
> of the with statement is basically an assignment with extras, and the
> original suggestion then combines multiple assignments on one line.
> This option, I think, is more concise and readable.
I prefer this also, for the same reasons.
tjr
More information about the Python-ideas
mailing list