Python - how can I get the class name from within a class method - using @classmethod

前端 未结 3 1951
太阳男子
太阳男子 2021-02-12 22:07

I have the following code:

class ObjectOne(object):
    @classmethod
    def print_class_name(cls):
        print cls.__class__.__name__

    def print_class_nam         


        
3条回答
  •  耶瑟儿~
    2021-02-12 23:07

    A classmethod receives the class as its argument. That's why you're calling it cls. Just do cls.__name__.

提交回复
热议问题