-1 python
我想基本上使用do函数将list元素转换为函数.这样任何预先编写的函数我都可以通过使用do(list [x])来调用.
我试图做的是一个函数,它取消了list元素的引号,然后执行该list元素中的函数.
def func():
print "python"
def func1():
print "is"
def func2():
print "awesome"
def do(fun):
fun()
#I think the problem is here
funs = ['func()','func1()','func2()']
print ''.join(funs[0])
do(''.join(funs[0]))
Run Code Online (Sandbox Code Playgroud)
编辑:
我试图做的是一个函数,它取消了list元素的引号,然后执行该list元素中的函数
您不需要额外的功能,也不需要将它们变成字符串:
def func():
print "python"
def func1():
print "is"
def func2():
print "awesome"
funcs = [func, func1, func2]
for function in funcs:
function()
Run Code Online (Sandbox Code Playgroud)