[Tutor] Just a newbie question...

Sean 'Shaleh' Perry shalehperry@attbi.com
Thu, 21 Feb 2002 09:28:58 -0800 (PST)


> 
> Also, is there a nice way to change this lousy code below?  I want to change
> it like a "switch" conditional statement in C, to display a "menu-like"
> choices.  What is a good alternative to "switch" of C in Python?  And what is
> a "good terminator" if I press "Q or q" in Python?
> 

menu = {1: fib, 2: mtable}

choice = raw_input("Enter a choice: ")
func = menu[choice]
func()

What this does is make a dictionary (hash table) where each choice is a key and
the value of the key is a function to run.