How to get the class instance of a passed method ?

Arnaud Delobelle arnodel at googlemail.com
Fri Nov 21 02:08:44 EST 2008


Christian Heimes <lists at cheimes.de> writes:

> Stef Mientki wrote:
>> hello,
>>
>> if I pass a class method to a function,
>> is it possible to determine the class instance in that  function ?
>>
>> class test ( object ) :
>>  def My_Method ( self ) :
>>    return 22
>>
>> def do_something ( parameter ) :
>>  # here I want to determine My_Instance
>>
>> My_Instance = test ()
>> do something ( My_Instance.My_Method )
>
>
>> >>> class Example(object):
> ...     def method(self):
> ...         pass
> ...
>>>> example = Example()
>>>> example.method.im_self
> <__main__.Example object at 0x7fc3cdb5b650>
>>>> example.method.im_class
> <class '__main__.Example'>
>>>> example.method.im_func
> <function method at 0x7fc3cdb566e0>

.im_self will become example.method.__self__ and in python 3.  But I
can't see the equivalen of .im_class?

-- 
Arnaud




More information about the Python-list mailing list