Switch statements again

Skip Montanaro skip at pobox.com
Thu Jan 16 00:13:15 CET 2003

    Steven> I've been reading the claims about doing things a more elegant
    Steven> way in python when it comes to switch statements, using
    Steven> if-elif-else and/or dictionaries of function pointers.  the
    Steven> following can be done with if-elif-else (and that's how I did
    Steven> it), but it sure is ugly.  my question is simply "what's the
    Steven> best way to do this in python?"

If/elif/else remains the most common method.  If Python ever gains something
like a switch statement you can bet the farm it won't have a "fall thru"
feature though, so the way you've coded your C switch statement wouldn't


More information about the Python-list mailing list