Gabriel Genellina wrote: > En Mon, 28 May 2007 06:17:39 -0300, ??????????????? > <[EMAIL PROTECTED]> escribió: > >> I wanna print the log to both the screen and file, so I simulatered a >> 'tee' >> >> class Tee(file): >> >> def __init__(self, name, mode): >> file.__init__(self, name, mode) >> self.stdout = sys.stdout >> sys.stdout = self >> >> def __del__(self): >> sys.stdout = self.stdout >> self.close() >> >> def write(self, data): >> file.write(self, data) >> self.stdout.write(data) >> >> Tee('logfile', 'w') >> print >>sys.stdout, 'abcdefg' >> >> I found that it only output to the file, nothing to screen. Why? >> It seems the 'write' function was not called when I *print* something. > > You create a Tee instance and it is immediately garbage collected.
It is not garbage collected until the next assignment to sys.stdout. Peter -- http://mail.python.org/mailman/listinfo/python-list