saving the text on python dos window.
Peter Otten
__peter__ at web.de
Thu Jun 24 08:21:41 EDT 2004
Daniel Dittmar wrote:
> class TeeStream:
> def __init__ (self, *outstreams):
> self.outstreams = outstreams
>
> def write (self, text):
> for outstream in self.outstreams:
> outstream.write (text)
Nice.
> # do the same for writelines, flush etc.
Or if you are really lazy, use this modification:
class Tee:
def __init__ (self, *instances):
self._instances = instances
def __getattr__(self, name):
def call(self, *args, **kw):
for i in self._instances:
getattr(i, name)(*args, **kw)
setattr(self.__class__, name, call)
return getattr(self, name)
It creates methods lazily on the fly as needed.
Peter
More information about the Python-list
mailing list