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 @   spotfg  阅读(266)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示