1 2# Override access to one variable in a class, but return all others normally 3# http://stackoverflow.com/a/371833/18852 4 5class D(object): 6 def __init__(self): 7 self.test = 20 8 self.test2 = 40 9 def __getattribute__(self, name): 10 if name == 'test': 11 return 0 12 else: 13 return object.__getattribute__(self, name) 14 15obj1 = D() 16print(obj1.test) 17print(obj1.test2) 18 19