在 Python 中,我尝试在一个类中运行一个方法,结果得到一个错误:
Traceback (most recent call last):
File "C:\Users\domenico\Desktop\py\main.py", line 8, in <module>
fibo.f()
TypeError: unbound method f() must be called with fibo instance
as first argument (got nothing instead)
代码: (swineflu.py)
class fibo:
a=0
b=0
def f(self,a=0):
print fibo.b+a
b=a;
return self(a+1)
脚本 main.py
import swineflu
f = swineflu
fibo = f.fibo
fibo.f() #TypeError is thrown here
这个错误是什么意思? 是什么导致了这个错误?