<br><br><div class="gmail_quote">On Tue, Oct 5, 2010 at 10:41 AM, Dave Angel <span dir="ltr"><<a href="mailto:davea@ieee.org">davea@ieee.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
 On 2:59 PM, Dirk Nachbar wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
How can I direct all print to a log file, eg some functions have their<br>
own print and I cannot put a f.write() in front of it.<br>
<br>
Dirk<br>
<br>
</blockquote>
<br>
When code does a print() without specifying a file, it goes to sys.stdout     So you just have to create a new file object and bind sys.stdout to it.<br>
<br>
(untested)<br>
<br>
import sys<br>
<br>
sys.stdout = open("mylogfile.txt", "w")<br>
or in your case   sys.stdout = f<br>
<br>
If you want to be able to go back to the original, then first bind another symbol to it.<br>
orig = sys.stdout<br>
sys.stdout = f<br>
----do stuff----<br>
sys.stdout = orig<br>
<br>
DaveA<br></blockquote><div><br>The original sys.stdout is stored as sys.__stdout__ so there's no need to store it yourself. <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<font color="#888888">
<br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>