Jon Clements wrote:
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
another alternative :
import types
if type(func) == types.MethodType:
pass
or possibly better
if isinstance(func, types.MethodType):
pass
JM
--
http://mail.python.org/mailman/listinfo/python-list