Switch statement

Joseph L. Casale jcasale at activenetwerx.com
Sun Mar 10 15:16:27 CET 2013


I have a switch statement composed using a dict:


switch = {
    'a': func_a,
    'b': func_b,
    'c': func_c
}
switch.get(var, default)()


As a result of multiple functions per choice, it migrated to:



switch = {
    'a': (func_a1, func_a2),
    'b': (func_b1, func_b2),
    'c': (func_c, )
}



for f in switch.get(var, (default, )):
    f()


As a result of only some of the functions now requiring unique arguments, I presume this
needs to be migrated to a if/else statement? Is there a way to maintain the switch style with
the ability in this scenario to cleanly pass args only to some functions?


Thanks,
jlc


More information about the Python-list mailing list