Dalam Python, saya mencoba menjalankan metode di kelas dan saya mendapatkan kesalahan:
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)
Kode: (swineflu.py)
class fibo:
a=0
b=0
def f(self,a=0):
print fibo.b+a
b=a;
return self(a+1)
Script main.py
import swineflu
f = swineflu
fibo = f.fibo
fibo.f() #TypeError is thrown here
Apa artinya kesalahan ini? Apa yang menyebabkan kesalahan ini?
fibo = f.fibo()
Perlu instanciate kelas dengan tanda kurung.
fibo().f()