[Python-Dev] Simple Switch statement

Raymond Hettinger raymond.hettinger at verizon.net
Sun Jun 25 20:13:37 CEST 2006

> Sorry, no go. You can say "supports key use cases found in real code"
> as often as you like,

Those were not empty words.  I provided two non-trivial worked-out examples 
taken from sre_constants.py and opcode.py.  Nick provided a third example from 
decimal.py.  In all three cases, the proposal was applied effortlessly resulting 
in improved readability and speed.  I hope you hold other proposals to the same 

> If you want to provide a solution for the constantification issue,
> let's discuss that first and then come back here.

No thanks.  That is its own can of worms.  The obvious solutions (like const 
declarations, macros, or a syntax to force compile-time expression evaluation) 
are unlikely to sit well because they run afoul Python's deeply ingrained 

The switch-case construct in C uses constant cases but depends on macros to make 
the constants symbolic.  Is that where we want to go with Python?  If so, that 
is most likely a Py3k discussion.

In contrast, the proposed simple switch statement is something we could have 
right away.  I will likely write-up a PEP and get a sample implementation so we 
can discuss something concrete at EuroPython.


More information about the Python-Dev mailing list