Write both in std output and in a file ?

Daniel Dittmar daniel.dittmar at sap.com
Wed Jan 16 04:50:14 EST 2002


> Is it possible to print output both in the console and in a file ?

class TeeStream:
    def __init__ (self, *streams):
        self.streams = streams

    def write (self, data):
        for stream in self.streams:
            stream.write (data)

call as
stream = TeeStream (sys.stdout, open ('...', 'wt'))

Daniel






More information about the Python-list mailing list