Re: Decorator pattern for new-style classes ?
- From: "Michele Simionato" <michele.simionato@xxxxxxxxx>
- Date: 24 Apr 2005 23:02:49 -0700
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
.
- References:
- Decorator pattern for new-style classes ?
- From: George Sakkis
- Decorator pattern for new-style classes ?
- Prev by Date: Re: What's do list comprehensions do that generator expressions don't?
- Next by Date: Re: What's do list comprehensions do that generator expressions don't?
- Previous by thread: Decorator pattern for new-style classes ?
- Next by thread: tracing function calls
- Index(es):
Relevant Pages
|