from types import MethodType, FunctionType


class Foo(object):
    def __init__(self):
        self.name = "MyName"

    def func(self):
        print(self.name)


obj = Foo()
print(isinstance(obj.func, FunctionType))  # False
print(isinstance(obj.func, MethodType))  # True   #说明这是一个方法

print(isinstance(Foo.func, FunctionType))  # True   #说明这是一个函数。
print(isinstance(Foo.func, MethodType))  # False

print(type(obj.func)) # <class 'method'>
print(type(Foo.func)) # <class 'function'>

 

 

REF

https://blog.csdn.net/qq_43422918/article/details/89645735

https://www.zhihu.com/question/317390856/answer/632194800

相关文章:

  • 2021-05-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-29
  • 2021-06-11
  • 2022-12-23
相关资源
相似解决方案