I may totally misunderstand what you're trying to do, but Python has a
way built in to capture output intp a Python data structure. If you
create a class with a write() method that takes a string argument, and
assign an instance of it to sys.stdout (and the same or another to
sys.stderr), then everything written by print statements (and
everything written explicitly to sys.stdout/stderr) is passed to the
instance instead, which can do as it please (e.g. display it in a
window if it has a windowing interface).
Maybe this helps...
--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>