Check是Class是继承检查的类型

时间:2018-02-04 12:30:10

标签: python python-3.x

有没有办法根据它们的继承检查python类而不实例化它?

class Base(object):
    pass

class slaveA(Base):
    pass

class slaveB(Base):
    pass


def test(a):
    # that's not correct 
    return type(slaveA) == type(a)


if __name__ == '__main__':

    print(test(slaveB)) # should be False
    print(test(slaveA)) # should be True
    print(test(Base))  # should be True

0 个答案:

没有答案