getting object name and function name

前端 未结 2 982
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 23:30

It is actually 2 questions. 1) Is there a generic way to get the class name of an instance, so if I have a class

class someClass(object):

2条回答
  •  醉梦人生
    2021-01-13 00:04

    the function part has already been answered at this SO post. The code would be:

    import sys
    print sys._getframe().f_code.co_name
    

    For the class part, use: A.__name__ or A().__class__.__name (for an instance)

提交回复
热议问题