Can we use print to print to more than sys.stdout?
Pierre Rouleau
prouleau at impathnetworks.com
Tue Mar 12 13:08:30 EST 2002
#1) Is it possible to change print behavior to make it print to several
streams?
I know it is possible to change the stream where print prints by
changing the value of sys.stdout, like this:
import sys
f = open('somefile', 'w')
sys.stdout = f
print 'whatever to that file'
f.close()
#then restore stdout
sys.stdout = sys.__stdout__
But is it possible, for example, to make it print both to stdout *and*
some file?
#2)
Is it also possible to define an object that would behave like a file
and that would do the printing itself to wherever required?
Thanks!
Pierre Rouleau
More information about the Python-list
mailing list