将函数存储为字典值时调用函数

che*_*ile 3 python python-2.7

def test():
     print "printing from test func"

dic = {'a':1,'b':2,'c':test}
if len(dic) == 3:
     print (dic['c'])

output:
<function test at 0x106887578>
Run Code Online (Sandbox Code Playgroud)

此代码打印函数对象作为输出,如何从测试函数获取print语句作为输出.

Blu*_*ode 13

只需调用dic['c']()即可运行您的功能.希望我帮忙!