In Python, how can you get the name of a member function's class?

后端 未结 5 478
小鲜肉
小鲜肉 2020-12-28 08:01

I have a function that takes another function as a parameter. If the function is a member of a class, I need to find the name of that class. E.g.

def analyse         


        
5条回答
  •  旧巷少年郎
    2020-12-28 08:58

    instance methods will have attributes .im_class .im_func .im_self

    http://docs.python.org/library/inspect.html#types-and-members

    You probably want to see if the function hasattr .im_class, and get the class info from there.

提交回复
热议问题