0
我想用timeit来计算三个相似的函数。我写了这段代码,但是我不明白当我将一个函数传递给测试函数时发生了什么。函数的传递函数获取NameError
def f0(x, y, z):
#some code here
def f1(x, y, z):
#a slighty similar function
def f2(x, y, z):
#still another similar function
def test(name):
x=100
y=100
z=100
res=name(x,y,z)
if __name__ == '__main__':
import timeit
print(timeit.timeit("test(f0)", setup="from __main__ import test"))
我得到的错误是:
NameError: global name 'f0' is not defined