【发布时间】:2017-02-22 01:39:33
【问题描述】:
我正在尝试从用户输入调用函数,但我正在努力弄清楚如何。例如,如果我运行程序并输入"3* foo",我希望返回输出("333333333333333333"),除非我得到TypeError: 'str' object is not callable;有什么想法吗?
def func3():
print ("333333333333333333")
command="3* foo" #command would be an input usually
f=command.split()
dic="1*":"func1", "2*":"func2", "3*":"func3"}
function_caller=(dic[f[0]])
(function_caller)()
错误:
TypeError: 'str' object is not callable
【问题讨论】:
标签: function python-3.x variables calling-convention