How to get a unique function name for methods

Christian Heimes lists at cheimes.de
Thu Oct 29 23:49:50 CET 2009


Philip Guo wrote:
> Does anyone know how to get this information either from a code object or
> from a related object?  I am hacking the interpreter, so I have full access
> to everything.

Does this help?

>>> class A(object):
...     def method(self):
...         pass
...
>>> A.method.im_class
<class '__main__.A'>
>>> A.method.im_class.__module__
'__main__'
>>> A.method.im_class.__name__
'A'
>>> A.method.im_func
<function method at 0x7f7655bc7a28>
>>> A.method.im_func.__name__
'method'
>>> '.'.join((A.method.im_class.__module__, A.method.im_class.__name__, A.method.im_func.__name__))
'__main__.A.method'




More information about the Python-list mailing list