"", "wrapper" . :
class F(object):
def __init__(self, func):
self.func = func
return
def __call__(self, *args, **kw):
print "Calling %r:" % self.func
print " args: %r" % (args,)
print " kw: %r" % kw
return self.func(*args,**kw)
class C(object):
def __init__(self):
self.a = 'an attribute that is not callable.'
return
def __getattribute__(self,name):
attr = object.__getattribute__(self,name)
if callable(attr):
return F(attr)
return attr
def m(self, *a, **kw):
print "hello from m!"
return
>>> c=C()
>>> c.a
'an attribute that is not callable.'
>>> c.m
<__main__.F object at 0x63ff30>
>>> c.m(1,2,y=25,z=26)
Calling <bound method C.m of <__main__.C object at 0x63fe90>>:
args: (1, 2)
kw: {'y': 25, 'z': 26}
hello from m!
>>>
Ants Aasma __getattribute__. all self, __getattribute__. self.__dict__ __getattribute__, , ! ,
__getattribute__ (, object.__getattribute__(self,name).)