0

给定 Python 3 中的方法句柄,我如何检索它所属的对象?

class Myclass:
    def foo(self):
        print(self, 'foo')

m = Myclass()

method_handle = m.foo
print(method_handle) # -> <bound method Myclass.foo of <__main__.Myclass object at 0x7fb80220dd10>>

该对象在某处method_handle引用了该实例。m但如果我只有method_handle,我如何检索m对象?

4

1 回答 1

1

Never mind, I just found it: it is in method_handle.__self__.

于 2013-11-02T18:22:42.820 回答