sys.stndout syntax
Calvelo Daniel
dcalvelo at pharion.univ-lille2.fr
Fri Aug 18 16:49:42 EDT 2000
d. savitsky <dsavitsk at e-coli.net> wrote:
: on win32, to get printed output to a file i use
:>>> sys.stndout = open('file.txt', 'w')
: how do i get it to go back to the command line,
sys.stdout = sys.__stdout__
: or better yet, how do i
: output to both at the same time?
On UNIX:
>>> class tee:
... def __init__(s, *targets):
... s.l = targets
... def write(s, what):
... for t in s.l:
... t.write( what )
...
>>> sys.stdout = tee( sys.__stdout__, open("t1",'w'), open("t2",'w') )
>>> print "works?"
works?
>>> #^D here
dcalvelo at lael:~/tmp$ cat t1
works?
dcalvelo at lael:~/tmp$ cat t2
works?
Should be portable to win32.
-- Daniel Calvelo Aros
calvelo at lifl.fr
More information about the Python-list
mailing list