[Python-ideas] switch statement as context manager?

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Feb 11 00:29:04 CET 2014


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?

-- 
Greg


More information about the Python-ideas mailing list