Alternative suggestion for conditional expressions (see PEP 308)
Pierre-Frédéric Caillaud
peufeu at free.fr
Mon Jul 19 13:31:07 EDT 2004
Flame suit on.
- add a switch-case statement :
I do miss a switch-case in Python.
The interpreter can't really optimize if/elif as a dictionary lookup,
because what if there is a AND or OR clause, or if the object has defined
a __cmp__ method with side effects ? This would be pervert...
switch color:
case 1:
name = 'red'
case 2:
name = 'blue'
case 3:
case 4:
name = 'colorblind'
Could use a 'break' (like in C) or not (cleaner).
- add a switch-case statement which can return a value.
Problem : you need a new keyword for that, which is a bad thing... and it
starts to look like lisp...
I think the ternary operator is a half-baked solution to a more general
problem ; it is useful as a little shortcut like " x ? 'Yes' : 'No' but
doing more with it leads to obfuscation.
Still, something lacks in Python... just like the break-n-levels.
More information about the Python-list
mailing list