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

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -