[Tutor] Redirecting Python Interpreter Output
Ketut Mahaindra
KMahaindra@beijing.sema.slb.com
Sun, 11 Aug 2002 10:55:00 +0800
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--Boundary_(ID_/hO1gunmB8QyqtTaxyfutA)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT
Hi,
Thanks, your suggestion give some shed of light to me ... :)
Since I am quite new to Python also,
I will need more in depth look on the StringIO class and
how to assign an object to the sys.stdout variable ... ;)
I will try it out, any help is greatly appreciated ...
especially if you're willing to make that "small apps"
that you mentioned previously ... :)
--
best regards
ito
@> -----Original Message-----
@> From: Danny Yoo [mailto:dyoo@hkn.eecs.berkeley.edu]
@> Sent: Sunday, August 11, 2002 10:45 AM
@> To: Ketut Mahaindra
@> Cc: 'tutor@python.org'; 'SA'
@> Subject: RE: [Tutor] Redirecting Python Interpreter Output
@>
@>
@>
@>
@> On Sun, 11 Aug 2002, Ketut Mahaindra wrote:
@>
@> > But now what if I want to catch the output from C++ ?
@> Anybody got any
@> > experience on this ?
@> >
@> > So, for example I have a PyRun_SimpleString() or
@> PyRun_SimpleFile or
@> > PyObject_CallObject on my C++ code ... Can I capture the
@> output of the
@> > Python interpreter ?
@>
@> Probably; what you can do is assign a file-like object to
@> the 'sys.stdout'
@> variable of your embedded interpreter. A
@> StringIO.StringIO() instance
@> should do nicely.
@>
@> Afterwards, once you allow the user to do a
@> PyRun_SimpleString(), you can
@> pull out what was written to stdout by looking into the StringIO's
@> contents.
@>
@> If you'd like, we can try to write a small sample
@> application that does
@> this, although I've haven't played with embedding Python before!
@>
--Boundary_(ID_/hO1gunmB8QyqtTaxyfutA)
Content-type: text/html; charset=iso-8859-1
Content-transfer-encoding: 7BIT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>RE: [Tutor] Redirecting Python Interpreter Output</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Hi,</FONT>
</P>
<P><FONT SIZE=2>Thanks, your suggestion give some shed of light to me ... :)</FONT>
</P>
<P><FONT SIZE=2>Since I am quite new to Python also,</FONT>
<BR><FONT SIZE=2>I will need more in depth look on the StringIO class and</FONT>
<BR><FONT SIZE=2>how to assign an object to the sys.stdout variable ... ;)</FONT>
</P>
<P><FONT SIZE=2>I will try it out, any help is greatly appreciated ...</FONT>
<BR><FONT SIZE=2>especially if you're willing to make that "small apps" </FONT>
<BR><FONT SIZE=2>that you mentioned previously ... :)</FONT>
</P>
<P><FONT SIZE=2>-- </FONT>
<BR><FONT SIZE=2>best regards</FONT>
</P>
<P><FONT SIZE=2>ito</FONT>
</P>
<P><FONT SIZE=2>@> -----Original Message-----</FONT>
<BR><FONT SIZE=2>@> From: Danny Yoo [<A HREF="mailto:dyoo@hkn.eecs.berkeley.edu">mailto:dyoo@hkn.eecs.berkeley.edu</A>]</FONT>
<BR><FONT SIZE=2>@> Sent: Sunday, August 11, 2002 10:45 AM</FONT>
<BR><FONT SIZE=2>@> To: Ketut Mahaindra</FONT>
<BR><FONT SIZE=2>@> Cc: 'tutor@python.org'; 'SA'</FONT>
<BR><FONT SIZE=2>@> Subject: RE: [Tutor] Redirecting Python Interpreter Output</FONT>
<BR><FONT SIZE=2>@> </FONT>
<BR><FONT SIZE=2>@> </FONT>
<BR><FONT SIZE=2>@> </FONT>
<BR><FONT SIZE=2>@> </FONT>
<BR><FONT SIZE=2>@> On Sun, 11 Aug 2002, Ketut Mahaindra wrote:</FONT>
<BR><FONT SIZE=2>@> </FONT>
<BR><FONT SIZE=2>@> > But now what if I want to catch the output from C++ ? </FONT>
<BR><FONT SIZE=2>@> Anybody got any</FONT>
<BR><FONT SIZE=2>@> > experience on this ?</FONT>
<BR><FONT SIZE=2>@> ></FONT>
<BR><FONT SIZE=2>@> > So, for example I have a PyRun_SimpleString() or </FONT>
<BR><FONT SIZE=2>@> PyRun_SimpleFile or</FONT>
<BR><FONT SIZE=2>@> > PyObject_CallObject on my C++ code ... Can I capture the </FONT>
<BR><FONT SIZE=2>@> output of the</FONT>
<BR><FONT SIZE=2>@> > Python interpreter ?</FONT>
<BR><FONT SIZE=2>@> </FONT>
<BR><FONT SIZE=2>@> Probably; what you can do is assign a file-like object to </FONT>
<BR><FONT SIZE=2>@> the 'sys.stdout'</FONT>
<BR><FONT SIZE=2>@> variable of your embedded interpreter. A </FONT>
<BR><FONT SIZE=2>@> StringIO.StringIO() instance</FONT>
<BR><FONT SIZE=2>@> should do nicely.</FONT>
<BR><FONT SIZE=2>@> </FONT>
<BR><FONT SIZE=2>@> Afterwards, once you allow the user to do a </FONT>
<BR><FONT SIZE=2>@> PyRun_SimpleString(), you can</FONT>
<BR><FONT SIZE=2>@> pull out what was written to stdout by looking into the StringIO's</FONT>
<BR><FONT SIZE=2>@> contents.</FONT>
<BR><FONT SIZE=2>@> </FONT>
<BR><FONT SIZE=2>@> If you'd like, we can try to write a small sample </FONT>
<BR><FONT SIZE=2>@> application that does</FONT>
<BR><FONT SIZE=2>@> this, although I've haven't played with embedding Python before!</FONT>
<BR><FONT SIZE=2>@> </FONT>
</P>
</BODY>
</HTML>
--Boundary_(ID_/hO1gunmB8QyqtTaxyfutA)--