[Baypiggies] code down sizing

Sean Perry shaleh at speakeasy.net
Fri Sep 1 23:39:43 CEST 2006


Brain Murphy wrote:
>   or something along those lines but I can not figure it out. Can any one help me with this?

What you want is a lookup device. Consider:

def do_a():
     import a
     # other code

def do_b():
     import b
     # other code

def do_c():
     import c
     # other code

choices = {'a': do_a,
            'b': do_b,
            'c': do_c,}
choice = raw_input("Enter choice: ")
action = choices[choice]
action()

(Rapidly entered but close to accurate ...)


More information about the Baypiggies mailing list