Reputation: 95
i've implemented a small code following a book for py33 in py35. I am trying to get the super classes instances from a given subclass as follows:
class Super:
def hello(self):
self.data1 = 'spam'
class Sub(Super):
def hola(self):
self.data2 = 'eggs'
X = Sub()
X.__dict__
X.__class__
X.__bases__
However, when i excecute the X.__bases__
command i get an error:
AttributeError: 'Sub' object has no attribute '__bases__'
Could someone explain to me why is this happening and how can I (if not so) get the instances of the superclasses of a given class?
Thanks to you all :)
Upvotes: 0
Views: 256
Reputation: 160427
You can get it from the class, not the instance, see the documentation of __bases__
:
class.__bases__
The tuple of base classes of a class object.
so, in short, use type(X).__bases__
.
Upvotes: 1