Find a common class python

Viewed 80

Having two python instances of some classes, let's say a is an instance of class A, and b is an instance of class B, is there an easy way to look for a common class for both objects? Also, since of course, all in Python inherits from 'object' I would like to know what the most 'specialized' common class.

I tried the following code, which seems to work:

def common_class(a,b):
    A = a.__class__
    B = b.__class__
    for i in A.mro():
        if i in B.mro():
            return i

But I was wondering if there exists an easier way to do it.

0 Answers
Related