Catching console output to string?

Robert Brotherus robert.brotherus at thermobio.com
Wed Nov 1 05:53:39 EST 2000


Thank you for your help!

At least in the Python environment, I got your proposed idea working. The
code:

import sys
print "Starting........."

class StringWriter:
    def __init__(self):
        self.x = ""
    def write(self, text):
        self.x += text

a = StringWriter()
print "First thing"
backup = sys.stdout
sys.stdout = a
print "Second thing"
print "Second thing - even now..."
sys.stdout = backup
print "Third thing"
print "String writer:",a.x

--------------------------------
Produces following (desired) output:

Starting.........
First thing
Third thing
String writer: Second thing
Second thing - even now...

I have to now get the same thing working from within the COM-component, but
I'm confident that it will work even there.

Thanks again,

Robert Brotherus





More information about the Python-list mailing list