If I have the following Python class:
class Test(object):
funcs = {
"me" : "action",
"action": "action",
"say" : "say",
"shout" : "say"
}
def dispatch(self, cmd):
def say:
print "Nested Say"
def action:
print "Nested Action"
# The line below gets the function name as a string,
# How can I call the nested function based on the string?
Test.funcs.get(cmd, "say")
I would like to be able to do the following:
>>> Test().dispatch("me")
Nested Action
>>> Test().dispatch("say")
Nested Say
Any suggestions as to how I can go about this?