How do I assign functions in a dictionary?
Posted
by Ziv
on Stack Overflow
See other posts from Stack Overflow
or by Ziv
Published on 2010-05-08T15:34:07Z
Indexed on
2010/05/08
15:38 UTC
Read the original article
Hit count: 172
python
hi, I'm having a problem with a simple program I wrote, I want to perform a certain function according to the users input. I've already used a dictionary as a replacement for a switch to do assignment but when I try to assign functions to the dictionary it doesn't execute them... The code:
def PrintValuesArea():
## do this
def PrintValuesLength():
## do that
def PrintValuesTime():
## do third
PrintTables={"a":PrintValuesArea,"l":PrintValuesLength,"t":PrintValuesTime}
PrintTables.get(ans.lower()) ## ans is the user input
what did I do wrong? It looks the same as all the examples I've seen....
© Stack Overflow or respective owner