Getattribute Example - Override access one attribute


Override access to one of the attribute of the object and return all other attributes from Super class.


# Override access to one variable in a class, but return all others normally

class D(object):
    def __init__(self):
        self.test = 20
        self.test2 = 40
    def __getattribute__(self, name):
        if name == 'test':
            return 0
            return object.__getattribute__(self, name)

obj1 = D()
print obj1.test
print obj1.test2
Run this
Comments by Disqus