[Python-ideas] with statement: multiple context manager
g.brandl at gmx.net
Mon Mar 2 09:10:41 CET 2009
Guido van Rossum schrieb:
> On Sun, Mar 1, 2009 at 1:15 PM, Calvin Spealman <ironfroggy at gmail.com> 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:
>> 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.
> -1 for this variant. The syntactic model is import: import foo as bar,
> bletch, quuz as frobl. If we're doing this it should be like this.
Also, the "a as b, c as d" syntax better conveys the fact that the managers
are called sequentially, and not somehow "in parallel".
More information about the Python-ideas