How to decide if a object is instancemethod?
Jon Clements
joncle at googlemail.com
Wed Mar 14 09:57:35 EDT 2012
On Wednesday, 14 March 2012 13:28:58 UTC, Cosmia Luna wrote:
> class Foo(object):
> def bar(self):
> return 'Something'
>
> func = Foo().bar
>
> if type(func) == <type 'instancemethod'>: # This should be always true
> pass # do something here
>
> What should type at <type 'instancemethod'>?
>
> Thanks
> Cosmia
import inspect
if inspect.ismethod(foo):
# ...
Will return True if foo is a bound method.
hth
Jon
More information about the Python-list
mailing list