How to get the parents of a Python class?

Use the following attribute:

cls.__bases__

From the docs:

The tuple of base classes of a class
object.

Example:

>>> str.__bases__
(<type 'basestring'>,)

Another example:

>>> class A(object):
...   pass
... 
>>> class B(object):
...   pass
... 
>>> class C(A, B):
...   pass
... 
>>> C.__bases__
(<class '__main__.A'>, <class '__main__.B'>)

Leave a Comment