First page Back Continue Last page Overview Graphics
Example __getattribute__() hook
class Example(object):
_p_state = False
def _p_activate(self):
print "activate"
self._p_state = True
def __getattribute__(self, attr):
print "intercept", attr
if not attr.startswith("_p_") and not self._p_state:
self._p_activate()
return super(Example, self).__getattribute__(attr)
>>> obj = Example(); obj.value = "test"
>>> print obj.value
intercept value
intercept _p_state
intercept _p_activate
activate
test
Notes: