Monkeypatching an object to become callable
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Mon Aug 10 04:08:32 EDT 2009
7stud a écrit :
(snip)
> class Wrapper(object):
> def __init__(self, obj, func):
> self.obj = obj
> self.func = func
>
> def __call__(self, *args):
> return self.func(*args)
>
> def __getattr__(self, name):
> return object.__getattribute__(self.obj, name)
This should be
return getattr(self.obj, name)
directly calling object.__getattribute__ might skip redefinition of
__getattribute__ in self.obj.__class__ or it's mro.
More information about the Python-list
mailing list