How to get instance given a method of the instance?

后端 未结 3 1784
执念已碎
执念已碎 2020-12-06 09:35
class MyClass:
    def myMethod(self):
        pass

myInstance = MyClass()

methodReference = myInstance.myMethod

Now can you get a reference to <

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-06 10:09

    Try this:

    methodReference.im_self
    

    If you are using Python 3:

    methodReference.__self__
    

提交回复
热议问题