0

Supposed I am given a variable pointing to a method of a class, is it possible to retrieve the variable pointing to its class?

For example, I have the following class,

class AClass(object):

    def __init__(self):
        pass

    @classmethod
    def class_method(cls):
        return None

    def instance_method(self):
        return None

    @staticmethod
    def static_method():
        return None

say, I am given only AClass.instance_method variable, is it possible to get Aclass based on that?

such that I could define a function with the following outcome.


def get_its_class(AClass.method):
   ....

   return AClass

And I hope such a function can work for class methods, static methods, and (instance) methods?

Yee.
  • 90
  • 7
  • does this answer your question?https://stackoverflow.com/questions/961048/get-class-that-defined-method – go2nirvana Nov 04 '20 at 17:23
  • @go2nirvana unfortunately no, im_class is no longer an attribute of a method in python 3. Also as I read the other comments of that post, it seems there might be some other implementations for python 3, which I will further check. – Yee. Nov 04 '20 at 17:56

0 Answers0