[IPython-user] replacing sys.stdout breaks prompt on windows

David Shilvock davels@telus....
Thu Nov 13 00:07:22 CST 2008


Python 2.5.2 on WinXP, IPython 0.9.1, latest pyreadline

I'm doing some work with the Mercurial api (written in python, similar to
bzr).  One of the main files that gets imported replaces sys.stdout with a
class that does a few basic checks but is otherwise a very thin wrapper
around sys.stdout.

Problem is, as soon as I import the file my prompt gets hosed (I can see the
raw ansi color codes, etc).  Here is a stripped down version of the problem:

In [1]:

import sys
class myout():
    def __init__(self, fp):
        self.fp = fp

    def __getattr__(self, key):
        return getattr(self.fp, key)

    def close(self):
        self.fp.close()

    def write(self, s):
        self.fp.write(s)

    def flush(self):
        self.fp.flush()

sys.stdout = myout(sys.stdout)
            
☺←[0;32m☻In [☺←[1;32m☻3☺←[0;32m☻]: ☺←[0m☻


I've looked through the IPython and pyreadline sources but I can't find
anything obvious that would explain this.  Does anyone have idea what the
problem is or any advice on where I should be looking in the source?

Thanks.

-- 
DS


More information about the IPython-user mailing list