Can we use print to print to more than sys.stdout?

Fredrik Lundh fredrik at pythonware.com
Tue Mar 12 14:25:14 EST 2002


Pierre Rouleau wrote:
> #1) Is it possible to change print behavior to make it print to several
> streams?

class Tee:
    def __init__(self, *streams):
        self.streams = streams
    def write(self, text):
        for stream in self.streams:
            stream.write(text)

sys.stdout = Tee(sys.stdout, open("some.file", "w"), ...)

</F>

<!-- (the eff-bot guide to) the python standard library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list