[Python-ideas] switch statement as context manager?

Ryan Gonzalez rymg19 at gmail.com
Tue Feb 11 17:49:59 CET 2014


On Tue, Feb 11, 2014 at 10:44 AM, Ned Batchelder <ned at nedbatchelder.com>wrote:

>
> On 2/11/14 10:37 AM, Ryan Gonzalez wrote:
>
> Because it doesn't *look *like one.
>
>
> If it *is* one, it's a good thing to *look* like one.
>
> PS: could you bottom-post?  It makes it easier to follow the thread.
> Thanks :)
>
> --Ned.
>
>
>
> On Tue, Feb 11, 2014 at 9:25 AM, Chris Angelico <rosuav at gmail.com> wrote:
>
>> 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
>>  _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
>
>
>  --
> Ryan
> If anybody ever asks me why I prefer C++ to C, my answer will be simple:
> "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was
> nul-terminated."
>
>
>
> _______________________________________________
> Python-ideas mailing listPython-ideas at python.orghttps://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>

Depends on whether or not you actually like the way it looks.

P.S. Sorry, GMail top-posts by default.

-- 
Ryan
If anybody ever asks me why I prefer C++ to C, my answer will be simple:
"It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was
nul-terminated."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140211/03bf6604/attachment.html>


More information about the Python-ideas mailing list