Multiple Inheritence and data attributes

Derek Basch dbasch at yahoo.com
Fri May 6 16:45:27 EDT 2005


Hello Everyone,

Given:

class A:
    def __init__(self):
        super(A, self).__init__()
        self.dog = "fluffy"
    def changeDog(self):
        self.dog = "spike"

class B:
    def __init__(self):
        super(B, self).__init__()

class C(object, A, B):
    def __init__(self):
        super(C, self).__init__()
    def printDog(self, cls):
        print cls.dog

c = C()
c.printDog(c)

How can I access data attributes of superclasses? I can see the
function attributes of the superclasses:

['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__module__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__',
'changeDog', 'printDog']

but not the data attributes. Shouldn't the derived class have that data
attributes of superclasses? I guess I am not understanding the python
implementation.

Thanks,
Derek




More information about the Python-list mailing list