如何在Python中查找绑定方法的实例? [英] How to find instance of a bound method in Python?

查看:139
本文介绍了如何在Python中查找绑定方法的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>>> class A(object):  
...         def some(self):  
...                 pass  
...  
>>> a=A()  
>>> a.some  
<bound method A.some of <__main__.A object at 0x7f0d6fb9c090>>

IOW,我需要在被移交a.some 。

IOW, I need to get access to "a" after being handed over only "a.some".

推荐答案

启动python 2.6可以使用特殊属性 __ self __

Starting python 2.6 you can use special attribute __self__:

>>> a.some.__self__ is a
True

im_self 已在py3k中淘汰。

im_self is phased out in py3k.

有关详情,请参阅 inspect

这篇关于如何在Python中查找绑定方法的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆