[Python-ideas] switch statement as context manager?

Chris Angelico rosuav at gmail.com
Tue Feb 11 16:25:28 CET 2014


On Wed, Feb 12, 2014 at 2:22 AM, Ryan Gonzalez <rymg19 at gmail.com> wrote:
> It looks cooler. It also feels slightly less aggravating.
>
>
> On Mon, Feb 10, 2014 at 5:29 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
> wrote:
>>
>> Sturla Molden wrote:
>>>
>>> I've noticed that PyExt has a switch statement implemented as a context
>>> manager.
>>>
>>> with switch(foobar):
>>>     if case(1): pass
>>>     if case(2): pass
>>
>>
>> What advantage does this have over an if-else chain?
>>
>

Since it fundamentally _is_ an if chain (without the elses), how does
it feel less aggravating than one?

ChrisA


More information about the Python-ideas mailing list