[Python-ideas] with statement: multiple context manager

Calvin Spealman ironfroggy at gmail.com
Sun Mar 1 22:15:45 CET 2009

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())


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.

Read my blog! I depend on your acceptance of my opinion! I am interesting!
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

More information about the Python-ideas mailing list