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)

5th May 2018, 6:29 AM
derzemel
3 Respostas
+ 1
you have to call the method otherwise you need to declare it out of the method
17th May 2018, 3:44 PM
$±𝐎â‚č𝔭!𝐹𝓝
$±𝐎â‚č𝔭!𝐹𝓝 - avatar
+ 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)
17th May 2018, 3:43 PM
$±𝐎â‚č𝔭!𝐹𝓝
$±𝐎â‚č𝔭!𝐹𝓝 - avatar
0
The Great Saga: thank you very much!
17th May 2018, 4:01 PM
derzemel