Get subclass name?

后端 未结 4 564
北海茫月
北海茫月 2021-01-03 22:23

Is it possible to get the name of a subclass? For example:

class Foo:
    def bar(self):
        print type(self)

class SubFoo(Foo):
    pass

SubFoo().bar         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-03 22:50

    SubFoo.__name__

    And parents: [cls.__name__ for cls in SubFoo.__bases__]

提交回复
热议问题