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__)
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__)
转载于:https://www.cnblogs.com/7134g/p/11536014.html