1 2# Override access to one variable in a class, but return all others normally 3 4class D(object): 5 def __init__(self): 6 self.test = 20 7 self.test2 = 40 8 def __getattribute__(self, name): 9 if name == 'test': 10 return 0 11 else: 12 return self.__dict__[name] 13 14# The above wont work. 15# This will give 16# RuntimeError: maximum recursion depth exceeded in cmp 17# Look at getattribute_example2.py for correct solution. 18 19obj1 = D() 20print(obj1.test) 21print(obj1.test2) 22 23 24