Check if a function is a method of some object

后端 未结 3 416
广开言路
广开言路 2021-02-07 13:52

How to check if a function is a method of some object?

For example:

def check_method(f):
    ...

check_method(lambda x: x + 1)           # >>>          


        
3条回答
  •  生来不讨喜
    2021-02-07 14:37

    It is also possible to check against the types defined in the built in types library:

    import types
    isinstance(obj.method, types.MethodType) # True
    

提交回复
热议问题