A similar question was asked here: ipython redirect stdout display corruption , but the answer is not satisfactory.
What I'm trying to do is capture standard output, write it to a PyQt4 QEditText while also sending it to the terminal as normal.
I'm using python 2.7 and Ubuntu 12.04 LTS.
The problem is that when I embed an IPython terminal inside the program, the terminal output text gets garbled and I lose autocomplete ability.
I was able to reproduce this issue very simply on my Ubuntu machine (the problem doesnt seem to exist on windows).
In my ubuntu termianl:
ipython
import IPython.utils.io
tee = IPython.utils.io.Tee('fds')
right here the text gets garbled while simply trying to use the Tee object.
In my program I do things a little differently, but it boils down to overwriting sys.stdout with a custom object and then when write or flush gets called I log the captured text and send it back to the original stdout and the PyQt4 gui.
So, is there a way to safely peek at standard out whenever the write or flush command gets called? And is there a way to do this that doesn't break IPython terminals?
It's due to special encoding for coloring of text in the terminal. Try using 'ipython --classic'.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.