I'm trying to hijack any calls made to my class and pass them to a method of my choice on the class.
My class so far:
class Klass(object):
def __getattribute__(self, name):
if name == '_dummy_func':
return object.__getattribute__(self, name)
return object.__getattribute__(self, 'dummy_func')
def _dummy_func(self):
print 'dummy func called!'
which works when I do this:
cls = Klass()
cls.foo()
but falls over when trying to do this:
cls = Klass()
cls.foo.bar()
as dummy_func
has no attribute bar
.
I looked at trying to catch this nested behaviour in the __getattribute__()
by checking to see if name
is a function as described here, however it's a string not the actual variable.
Is there a way to catch this from inside Klass
?