python动态添加属性

class A:
    def __init__(self, info ={}):
        self.info = info

    def __getattr__(self, item):
        return self.info[item]


a =A()
a.age = 123
print(a.age)
a.name = 123
print(a.name)
a.xis = 123
print(a.xis)
print(a.__dict__)

 

posted @ 2019-09-17 18:22  spotfg  阅读(266)  评论(0编辑  收藏  举报