Write both in std output and in a file ?

Ruediger Maehl ruediger.maehl_nospam at web.de
Thu Jan 17 10:14:54 EST 2002


"Daniel Dittmar" <daniel.dittmar at sap.com> schrieb im Newsbeitrag
news:a23icn$249$1 at news1.wdf.sap-ag.de...
> 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

Very smart!

Is there an easy way to implement, that a timestamp is also
printed for each print that I call without having to specify it in the
print statement itself?

The statement:

print "Hello", 1, "more here"

should produce (in stdout and in the file):

2002-01-17 16:10:22 Hello 1 more here

Rüdiger





More information about the Python-list mailing list