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

前端 未结 3 1953
太阳男子
太阳男子 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 22:47

    It's cls.__name__. cls already points to the class, and now you're getting the name of its class (which is always type).

提交回复
热议问题