[Python-ideas] A real limitation of contextlib.nested()

Georg Brandl g.brandl at gmx.net
Sun Mar 15 20:18:51 CET 2009

Ron Adam schrieb:
> Nick Coghlan wrote:
>> Dedicated syntax (such as the form that Christian proposed) would fix
>> this problem:
>>   with lock, (open(infile) as fin), (open(outfile, 'w') as fout):
>>       fout.write(fin.read())
> Could 'and' possibly be used sense it is a flow control operator in python.
>     with lock
>            and open(infile) as fin
>            and open(outfile, 'w' as fout:
>        fout.write(fin.read())

But it isn't a control flow operator. It is a boolean operator, and since
"with" expressions are expressions, it's perfectly valid there.


Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.

More information about the Python-ideas mailing list