我需要的是获取变量的东西,如果变量是函数的名称,则将调用该函数.我不是试图从模块中获取函数,而是从程序本身中获取函数
例:
def foo():
print("Foo")
callfunction = input("What function do you want to call? ")
callfunction() ## Not sure what to put here but but lets say callfunction is foo.
Run Code Online (Sandbox Code Playgroud)
我不想要这样的东西,因为我有很多功能:
if callfunction == "Foo"
Foo()
else:
print("No function with that name")
Run Code Online (Sandbox Code Playgroud)
我的问题是这样的,但我要求Python语法.我使用的是Python 3.5.1