redirecting stdout to a file as well as screen

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Apr 12 06:16:48 EDT 2007


En Thu, 12 Apr 2007 06:01:18 -0300, SamG <mad.vijay at gmail.com> escribió:

> On Apr 12, 1:00 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> wrote:
>> En Thu, 12 Apr 2007 04:14:32 -0300, SamG <mad.vi... at gmail.com> escribió:
>>
>> > How could i make, from inside the program, to have the stdout and
>> > stderr to be printed both to a file as well the terminal(as usual).
>>
>> class Tee(file):
>>      others = ()
>>
>>      def write(self, data):
>>          file.write(self, data)
>>          for f in others:
>>              f.write(data)
>>
>
> This is only creating an out.log file and all the stdout and stderr
> are logged there.

Sorry, `for f in others:` should read `for f in self.others:`

-- 
Gabriel Genellina




More information about the Python-list mailing list