python - Check if a function is a method of some object -
how check if function method of object?
for example:
def check_method(f): ... check_method(lambda x: x + 1) # >>> false check_method(someclass().some_method) # >>> true
there special attributes in methods in 'helloworld' example (e.g. 'im_self', '__self__' etc). can rely on them or there nicer way?
use inspect.ismethod()
.
the documentation states:
return true if object bound method written in python.
this means work intend classes define in python. however, methods of built-in classes list
or classes implemented in extension modules return false
.
Comments
Post a Comment