[Python-ideas] with statement: multiple context manager

Guido van Rossum guido at python.org
Thu Mar 26 16:14:44 CET 2009


On Thu, Mar 26, 2009 at 8:07 AM, Mathias Panzenböck
<grosser.meister.morti at gmx.net> wrote:
> Sturla Molden wrote:
>> On 3/1/2009 9:57 PM, Christian Heimes wrote:
>>
>>>   with a, b as x, d as y:
>>
>> I'd like to add that parentheses improve readability here:
>>
>>    with a, (b as x), (d as y):
>>
>> I am worried the proposed syntax could be a source of confusion and
>> errors. E.g. when looking at
>>
>>    with a,b as c,d:
>>
>> my eyes read
>>
>>    with nested(a,b) as c,d:
>>
>> when Python would read
>>
>>    with a,(b as c),d:
>>
>>
>
> Good point. Maybe that would be better:
>
>   with a,b as c,d:
>
> reads as:
>
>   with nested(a,b) as c,d:
>
> This means there can only be one "as" in a with statement with the further
> implication that even unneeded values have to be assigned:
>
>   with a,b,c as x,unused,y:
>
> Not as nice, but much more unambiguous. Unambiguity is what we need, I
> think. You can always assing to _, wich is very commonly used for unneeded
> values (well, or for the l10n hook - so using that name would not be very
> unambiguous).

No, we should maintain the parallel with" import a, b as c, d".

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list