Get subclass name?

后端 未结 4 533
北海茫月
北海茫月 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:57

    you can use

    SubFoo().__class__.__name__
    

    which might be off-topic, since it gives you a class name :)

提交回复
热议问题