Mike wrote:
I should've mentioned I want StdoutLog to subclass the 'file' type because I need all the file attributes available.
You might use a surrogate pattern. Here's one I use for this kind of situation, where I want to subclass but that can't be done for some reason.
class SurrogateNotInitedError(exceptions.AttributeError):
passclass Surrogate(object):
def __init__(self, data):
self._data = data def __getattr__(self, name):
if name == "_data":
raise SurrogateNotInitedError, name
else:
try:
return getattr(self._data, name)
except SurrogateNotInitedError:
raise SurrogateNotInitedError, nameI'll leave it as an exercise to the reader to make this work when self._data is actually a list of objects instead of a single object. You'll obviously need special logic for different methods, like write(), since for some of them you will want to call every object in self._data, and others only a single object.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list
