List all base classes in a hierarchy of given class?

后端 未结 7 1053
清歌不尽
清歌不尽 2020-11-28 02:28

Given a class Foo (whether it is a new-style class or not), how do you generate all the base classes - anywhere in the inheritance hierarchy -

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 02:43

    inspect.getclasstree() will create a nested list of classes and their bases. Usage:

    inspect.getclasstree(inspect.getmro(IOError)) # Insert your Class instead of IOError.
    

提交回复
热议问题