Python中的类继承

Ale*_*ell 5 python inheritance attributes

我是python的新手,并试图获取对象类继承的类的列表.我正在尝试使用该bases属性执行此操作,但我没有取得任何成功.有人可以帮帮我吗?

def foo(C):
     print(list(C.__bases__))

class Thing(object):
    def f(self):
        print("Yo")

class Shape(Thing):
    def l(self):
        print("ain't no thang")

class Circle(Shape):
    def n(self):
        print("ain't no shape")

test = Circle()
foo(test)
Run Code Online (Sandbox Code Playgroud)

nne*_*neo 6

只有课程__bases__; 类实例没有.您可以通过实例获取类对象__class__:use foo(test.__class__)foo(Circle).