[Python-ideas] with statement syntax forces ugly line breaks?

Mathias Panzenböck grosser.meister.morti at gmx.net
Thu Sep 9 15:02:24 CEST 2010


On 09/09/2010 02:17 PM, Georg Brandl wrote:
> Am 09.09.2010 09:55, schrieb Ben Finney:
>> "Gregory P. Smith"<greg at krypto.org>
>> writes:
>>
>>> On Wed, Sep 8, 2010 at 10:00 AM, Nathan Schneider<nathan at cmu.edu>  wrote:
>>>> I have approached these cases by using the backslash line-continuation
>>>> operator:
>>>>
>>>> with FakeContext("a") as a, \
>>>>    FakeContext("b") as b:
>>>>    pass
>>>
>>> I'm in the "\ is evil" at all costs camp […]
>>
>> I agree, especially when we have a much neater continuation mechanism
>> that could work just fine here::
>>
>>      with (FakeContext("a") as a,
>>               FakeContext("b") as b):
>>           pass
>
> No, it could not work just fine.  You are basically banning tuples from the
> context expression (remember that the "as" clause is optional).
>
> Maybe one could argue that this is not a problem because tuples are not
> context managers anyway, but how would this work then:
>
> i = 0 or 1
> with (a, b)[i]:
>
> Georg
>

Just write:
with ((a, b)[i]):

It's ugly but it would work. ;)

	-panzi



More information about the Python-ideas mailing list