【问题标题】:How do I retrieve the object a method handle is bound to? [duplicate]如何检索方法句柄绑定到的对象? [复制]
【发布时间】:2013-11-13 17:48:17
【问题描述】:

给定 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 对象?

【问题讨论】:

    标签: python python-3.x introspection


    【解决方案1】:

    没关系,我刚刚找到它:它在method_handle.__self__

    【讨论】:

      猜你喜欢
      • 2013-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多