Python 获取类对象的父类
参考
Python 获取类对象的父类
给定一个类的对象a
,要求获取该对象的父类。
方法:
a.__class__.__bases__
返回由该对象的父类组成的元组,例如:
>>> class Base(object):
... pass
...
>>> class Derived(Base):
... def print_base(self):
... for base in self.__class__.__bases__:
... print base.__name__
...
>>> foo = Derived()
>>> foo.print_base()
Base
2019.1
To improve is to change, to be perfect is to change often.