Decorator pattern for new-style classes ?
Michele Simionato
michele.simionato at gmail.com
Mon Apr 25 02:02:49 EDT 2005
I have no time for a long discussion, but the code should
speak for itself:
class Container(object):
def __init__(self, content):
self.content = content
def __str__(self):
return "<Container containing %r>" % self.content
class Wrapped(object):
def __init__(self, obj):
self._obj = obj
def __getattribute__(self, name):
obj = super(Wrapped, self).__getattribute__("_obj")
return getattr(obj, name)
w = Wrapped(Container("hello"))
print w.content
print w.__str__() # works
print w # does not work as you would expect, see bug report SF 729913
The discussion around the bug report is worth reading,
Michele Simionato
More information about the Python-list
mailing list