3
I have a little doubt about the issue of inheritance in python.
In the following test, I hoped that quack prints the same value for the two classes I created:
class A(object):
a,b = (None, None)
def __init__(self):
self.a = 'a'
def quack(self):
return 'retorno "%s" ' % self.a
class B(A):
def __init__(self):
super(A, self).__init__()
self.b = 'b'
My test was done like this:
b = B()
a = A()
print(b.quack())
print(a.quack())
The exit was:
retorno "None"
retorno "a"
But I thought the two should return to the same thing.
The inheritance of property a only worked as I expected when I changed the section of super for that reason:
A.__init(self)
Return:
retorno "a"
retorno "a"
Having these two cases, what is the difference between the two statements I created?
Why didn’t the super use the parent class method?
Your exit is not changed no? The return
Noneis for classBand theais for classA, right?– mgibsonbr
'Cause my print is reversed, I’m posting it
– Wallace Maxters
@mgibsonbr realized that when I changed to
super(B, self)worked. I guess I didn’t understand why the super server :\– Wallace Maxters
Haha didn’t see your comment, and I ended up posting a reply saying exactly that... P
– mgibsonbr