Subclassing a read-only class
Jason Orendorff
jason at jorendorff.com
Mon Feb 18 14:38:18 EST 2002
Gerhard Häring wrote:
> I'm pretty sure there is a solution, probably with a proxy object.
You are exactly correct. The basic pattern is like this:
class Proxy:
def __init__(self, obj):
self.__obj = obj
def __getattr__(self, name):
return getattr(self.__obj, name)
def __setattr__(self, name, value):
setattr(self.__obj, name, value)
... your extra methods here ...
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list