Get name of current class?

后端 未结 7 2191
有刺的猬
有刺的猬 2020-12-04 23:21

How do I get the name of the class I am currently in?

Example:

def get_input(class_name):
    [do things]
    return class_name_result

class foo():
         


        
7条回答
  •  星月不相逢
    2020-12-04 23:42

    You can access it by the class' private attributes:

    cls_name = self.__class__.__name__
    

    EDIT:

    As said by Ned Batcheler, this wouldn't work in the class body, but it would in a method.

提交回复
热议问题