Executing a function based on user-input
Ramachandran Subramanian
rsubramanian at eudoramail.com
Mon Jun 5 20:54:04 EDT 2000
I have a number of functions. Based on user input (a number) from a
menu, I want to execute one of these functions.
The C++ way is to use a switch statement or a table of functions.
In Python, the brute-force way is to use if ... elif ... elif... else...
. Since I was not happy with this scheme, I am currently using a
dictionary to store these functions and use the user input as the key
into this dictionary to select the function to execute and use the apply
built-in function to execute the selected function.
Is there a better way to do this?
Thanks
More information about the Python-list
mailing list