特殊方法

特殊方法

class Foo(object):
    def __getattr__(self, item):
        print(item)
        return '__getattr__'


obj = Foo()
print(obj.method)
# 输出:
method
__getattr__
  • 将method当作参数传入'__getattr__'方法中,而'__getattr__'方法所返回的内容就是obj.method方法所返回的内容
posted @ 2023-08-15 21:09  f_carey  阅读(8)  评论(0编辑  收藏  举报