By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,932 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

Re: How to get the class instance of a passed method ?

P: n/a
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

Nov 20 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Christian Heimes <li***@cheimes.dewrites:
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

Nov 21 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.