0
Object has no attribute. Why?
I have this simple Python 3 code. I define 3 classes: class Test2 inherited class Test1 and class Test3 inherited Test2. When I create an object for class Test3 and try to print it with the attribute "doi" from Class Test3, it error's out: the object has no attribute "doi" Why? class Test1: def metoda1(self): self.unu='unu' class Test2(Test1): def metoda2(self): self.unu='doi' class Test3(Test2): def metoda3(self): self.doi='doi' obj=Test3() print(obj.doi)
3 Réponses
+ 1
you have to call the method otherwise you need to declare it out of the method
+ 1
class Test1:
def metoda1(self):
self.unu='unu'
class Test2(Test1):
def metoda2(self):
self.unu='doi'
class Test3(Test2):
def metoda3(self):
self.doi='doi'
obj=Test3()
obj.metoda3()
print(obj.doi)
0
The Great Saga: thank you very much!