Подтвердить что ты не робот

Как найти пример связанного метода в Python?

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

IOW, мне нужно получить доступ к "a" после передачи только "a.some".

4b9b3361

Ответ 2

>>> class A(object):
...   def some(self):
...     pass
...
>>> a = A()
>>> a
<__main__.A object at 0x7fa9b965f410>
>>> a.some
<bound method A.some of <__main__.A object at 0x7fa9b965f410>>
>>> dir(a.some)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__format__', '__func__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'im_class', 'im_func', 'im_self']
>>> a.some.im_self
<__main__.A object at 0x7fa9b965f410>

Ответ 3

Попробуйте выполнить следующий код и посмотрите, если он вам поможет:

a.some.im_self

Ответ 4

Вы хотите что-то вроде этого, я думаю:

>>> a = A()
>>> m = a.some
>>> another_obj = m.im_self
>>> another_obj
<__main__.A object at 0x0000000002818320>

im_self - объект экземпляра класса.