In python how to get name of a class inside its static method

前端 未结 2 671
借酒劲吻你
借酒劲吻你 2021-02-05 04:18

how to get name of a class inside static method, i have inheritance and want name of derived class

IN following example what shall be there in place of XXX

2条回答
  •  隐瞒了意图╮
    2021-02-05 04:38

    I'm pretty sure that this is impossible for a static method. Use a class method instead:

    class Snake(object):
        @classmethod
        def my_name(cls):  
            print cls.__name__
    

提交回复
热议问题