Issue of redirecting the stdout to both file and screen

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon May 28 11:47:30 EDT 2007


En Mon, 28 May 2007 09:10:40 -0300, Peter Otten <__peter__ at web.de>  
escribió:

> Gabriel Genellina wrote:
>
>> En Mon, 28 May 2007 06:17:39 -0300, ???????????????
>> <kelvin.you at gmail.com> escribió:
>>
>>>     def __init__(self, name, mode):
>>>         file.__init__(self, name, mode)
>>>         self.stdout = sys.stdout
>>>         sys.stdout = self
>>>
>>> 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.

Yes, sorry, this was my first guess. Later I discovered the real reason  
-you pointed it too-, I should have removed the whole first paragraph on  
my reply.

-- 
Gabriel Genellina




More information about the Python-list mailing list