python变量输入自定义函数调用

时间:2017-02-22 01:39:33

标签: function python-3.x variables calling-convention

我试图从用户输入调用函数,但我正在努力弄清楚如何。例如,如果我运行程序并输入"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

0 个答案:

没有答案