Inheritance, __getattr__...?
Gerrit Holl
gerrit.holl at pobox.com
Sun Dec 26 10:12:53 EST 1999
Hello,
I currently have a subclass of UserDict with the following methods:
...
def __setitem__(self, key, value):
UserDict.__setitem__(self, key, value)
if not self.buffered:
self.flush()
def __delitem__(self, key):
UserDict.__delitem__(self, key)
if not self.buffered:
self.flush()
def clear(self):
UserDict.clear(self)
if not self.buffered:
self.flush()
...
As you can see, I'm looking for a construct:
For every method, first do the method of base class UserDict and next
do <THIS> code.
I think I'm close with this code:
class MyClass(UserDict.UserDict):
def method(*args, **kw):
apply(UserDict.??????, args, kw)
if not self.buffered:
self.flush()
__setitem__ = __getitem__ = __delitem = __del__ = \
keys = values = has_key = get = update = method # for all methods...
But I don't know what to put in apply(...)
Should I just be content with the first code, which is IMHO ugly?
regards,
Gerrit.
--
"The world is beating a path to our door"
-- Bruce Perens, (Open Sources, 1999 O'Reilly and Associates)
3:33pm up 5:04, 16 users, load average: 0.00, 0.00, 0.00
More information about the Python-list
mailing list