On Tue, Dec 8, 2009 at 8:53 PM, hong zhang <henryzhan...@yahoo.com> wrote:
> List,
>
> Python does not have switch statement. Any other option does similar work?
> Thanks for help.
>


Use a dict instead, where the keys are the different cases and the
values are usually callable objects (such as functions)
options = {"a" : do_a, "b",do_b, "c", do_c}

option = "a"

try :
    options[option]()
except KeyError :
    do_default()





> --henry
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to