C and C++ have:
switch(value)
{
case 1: do_stuff; break;
case 2:
case 3: do_stuff_2(); break;
default: break;
}
2014-02-11 17:44 GMT+01:00 Ned Batchelder <ned@nedbatchelder.com>:
If it is one, it’s a good thing to look like one.
well, you also get to remove the repeated variable name.
but a real switch statement should take advantage of python’s hashing. the best we have is
def _handle_spam(): vomit() def _handle_eggs(): yum() handlers = { 'spam': _handle_spam, 'eggs': _handle_eggs, } handlers[food]()
which makes me
_handle_spam()
.
the problem of a real switch statement is apparently that there’s no good syntax:
switch food case 'spam': ...
is strange due to the missing colon. we have that nowhere in python. yet
switch food: case 'spam': ...
is strange because after the colon, everywhere else is an indentation. but
switch food: case 'spam': ...
is indentation overkill. nobody has found a good syntax yet.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/