If you want the name of it:
boundmethod.im_class.__name__
Or in python 3:
boundmethod.__self__.__class__.__name__
Вопрос
In pyton code I've got a bound method of some object. Knowing only this bound method I would like to know what is the class of that object. Is it possible?
Here is sample code:
>>> class x:
... def method(self):
... pass
...
>>> x
<class __main__.x at 0xb737d1ac>
>>> x_instance = x()
>>> x_instance
<__main__.x instance at 0xb737c7cc>
>>> boundmethod = x_instance.method
>>> boundmethod
<bound method x.method of <__main__.x instance at 0xb737c7cc>>
>>> str(boundmethod)
'<bound method x.method of <__main__.x instance at 0xb737c7cc>>'
Let's assume I know only boundmethod
. How to determine that the class is x
?
Решение
If you want the name of it:
boundmethod.im_class.__name__
Or in python 3:
boundmethod.__self__.__class__.__name__