[Tutor] solution to dynamic proxy in python
Ashish
asis@graffiti.net
Sat, 06 Jul 2002 21:00:14 +0545
well, i think i have my answer. i saw the special function __getattr__
but did not think it would work for functions too.
anyway, as i was scanning through thinking in python by bruce eckel i
found an implementation of dynamic proxy. cool!
i am really looking forward to thinking in python. i think it will be
one of the coolest python book.
anyway to all who want to see an example:
class RealClass:
def func1(self):
print 'func1@RealClass'
def func2(self, arg):
print 'func2@RealClass with arg:', arg
class Proxy:
def __init__(self):
self.__real = RealClass
def __getattr__(self, name):
return getattr(self.__real, name)
ashish