0

I'm very new to python. I'm trying to execute the following code but getting error. As per my understanding C Class inherits from A and B. So it should have the instance variables from both. Could you please help me out?

class A:
    def __init__(self):
        self.bar = "Bar"
        self.name = "Gautam"

class B:
    def __init__(self):
        self.foo = "Foo"
        self.name = "Nayak"

class C(A, B):
    def __init__(self):
        super().__init__()
    def showProps(self):
        print(self.name, self.bar, self.foo)

c = C()
c.showProps()

Error: AttributeError: 'C' object has no attribute 'foo'

thegautamnayak
  • 287
  • 4
  • 15
  • https://stackoverflow.com/questions/3277367/how-does-pythons-super-work-with-multiple-inheritance – PM 77-1 Jun 24 '21 at 16:29
  • Please return to your materials on classes, especially where it shows you how `super` is resolved. The key phrase is **MRO**: Module Resolution Order. `super` refers to the first available reference in that list -- *not* to each of them in some sequence. – Prune Jun 24 '21 at 16:29
  • The stack overflow answer linked to above contains some good resources. This talk by Raymond Hettinger is also great: https://www.youtube.com/watch?v=EiOglTERPEo&ab_channel=PyCon2015 – Alex Waygood Jun 24 '21 at 16:36

0 Answers0