How to determine the closest common ancestor class
问题 Suppose I have four classes: A , B derived from A , C derived from A , and D derived from C . (So I always have single inheritance.) In python, what is the best way to determine the closest common ancestor of any two (instances of such) classes? Specifically, I need a function clcoancl(X,Y) for which clcoancl(A, B) == A , clcoancl(B, C) == A , and clcoancl(C, D) == C . 回答1: This should work for single or multiple inheritance, with any number of classes as input: import inspect from