在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
这个错误是什么意思?是什么导致此错误?
fibo = f.fibo()
需要用方括号实例化该类。
fibo().f()