Propagating function calls
clp2 at rebertia.com
Wed Feb 11 02:10:40 CET 2009
On Tue, Feb 10, 2009 at 5:02 PM, Noam Aigerman <noama at answers.com> wrote:
> Suppose I have a python object X, which holds inside it a python object Y.
> How can I propagate each function call to X so the same function call in Y
That'd be a method call actually, not a function call.
> will be called, i.e:
> Would cause
Use a simple proxy (this will forward attribute accesses too, but that
doesn't usually matter and can be worked around if necessary):
def __init__(self, delegate):
self.delegate = delegate
def __getattr__(self, attr):
return getattr(self.delegate, attr)
Note that this won't forward the operator special methods (e.g. __add__).
Follow the path of the Iguana...
More information about the Python-list