我正在努力解决这个问题。
所以这就是我想要做的:
我有三个功能。
说,foo,bar 和 foo_bar
def foo_bar(function):
for i in range(20):
function # execute function
def foo(someargs):
print "hello from foo"
def bar(someargs):
print " hello from bar"
当我做
foo_bar(foo)
# how to specify arguments to foo??
我期待我看到
"hello from foo" 20 times
?但因为我没有看到......我显然不太明白这一点?
最佳答案
你不是在调用函数。您可以通过在名称 function
后面加上括号 function
来调用名为 ()
的函数,并在这些括号内放置您需要的任何参数:
function(function)
我已将函数作为参数传递给自身,因为您的
foo
和 bar
接受参数,但对它们不做任何处理。关于python - 在python中将函数作为参数传递,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18991362/