This variation works:
#------------------------------------------------------------------------
class Tee:
    def __init__(self, *args):
        self.files = args

    def write(self, data):
        for f in self.files:
            result = f.write(data)
        return result

    def writelines(self, seq):
        for i in seq: self.write(i)

import sys
sys.stdout = Tee(sys.stdout, open("/tmp/stdout.log", "w"))

print 'STDOUT', sys.stdout
#------------------------------------------------------------------------

It appears that the 'print' statement always uses file.write if
isinstance(sys.stdout, file).  I don't know whether this has been
reported as a bug before, or if there's a reason for the current
behavior.  It may be an accidental behavior that is left over from the
days when builtin types were not subclassable.

Jeff

Attachment: pgp7JrGs05dLk.pgp
Description: PGP signature

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to