<br><br><div class="gmail_quote">On Mon, Feb 9, 2009 at 10:40 AM, Laurent Dufréchou <span dir="ltr"><<a href="mailto:laurent.dufrechou@gmail.com">laurent.dufrechou@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="FR">
<div>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Hi Dan,</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">From what I've seen of ipython code, seems right for me,
so the idea is to keep sending to sys.stdout because ipython redefine it.</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">So, the only problem I see with your code is that you use </span><span lang="EN-US">sys.__stdout__ that always return the python initial stdout and not
the one ipython use.</span></p>
<p><span lang="EN-US">So on your code you where sending your log
to the original stdout without passing by ipython function, that's why
you get the messy output.</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US"> </span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);" lang="EN-US">Have you tried something like (not tested yet):</span></p>
<p>ipython_sys_stdout = sys.stdout<span style="font-size: 11pt; color: rgb(31, 73, 125);"></span></p>
<p>sys.stdout = multicaster(,'LogFile.txt', ipython_sys_stdout)</p>
<p>?</p></div></div></blockquote><div><br><br>Laurent, thanks for your message. Unfortunately I think this suggestion doesn't work. (I did try it, and the same result occurs -- that is, pressing the "up" key gives \[[A, etc....). I also tried using slightly more sophisticated multicaster definition (code included below) which catches all attributes of the old sys.stdout and (except for the "write" method) directs to the to the old one. Even using this, I sitll get the _same_ resulting weird behavior. <br>
<br></div></div>I think that actually sys.stdout and sys.__stdout__ are the same in an ipython session, and that something else is going on. (But i'm not sure what.) <br><br><br><br>class multicaster():<br> def __init__(self,filename,OldObject,New=False):<br>
<div id=":7t" class="ArwC7c ckChnd"> self.file = filename<br> self.old = OldObject<br> <br> if New:<br> F = open(filename,'w')<br> F.write('\n\n------------------------------------------------------------------------------------------------------------------------------------------------------\n')<br>
F.write('STARTING LOG: ' + time.strftime('%c %Z') + '\n')<br> F.write('------------------------------------------------------------------------------------------------------------------------------------------------------\n\n')<br>
F.close()<br> <br> def __getattr__(self,name):<br> if name != 'write':<br> return self.old.__getattribute__(name)<br> <br> def write(self,s):<br> F = open(self.file,'a')<br>
F.write(s)<br> F.close() <br> return self.old.write(s)</div><br>