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