How to get the class instance of a passed method ?
Christian Heimes
lists at cheimes.de
Thu Nov 20 18:30:34 EST 2008
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>
Christian
More information about the Python-list
mailing list