setattr和getattr的理解

class A(object):

    def __init__(self):
        # self.x1 = {}
        object.__setattr__(self, "x", {})

    # def __getattr__(self, item):
    #     print(item)

    def __setattr__(self, key, value):
        print(self.x)
        print(key, value)
        self.x[key] = value
        print(self.x)


a = A()
a.name = "chr"
发布了140 篇原创文章 · 获赞 53 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_44291044/article/details/104479001