Is the `code` module (<a href="http://docs.python.org/library/code.html">http://docs.python.org/library/code.html</a>) an insufficiently exact copy of an interpreter for you?<br><br><div class="gmail_quote">On Mon, Aug 8, 2011 at 4:17 PM, Francis Labarre <span dir="ltr"><<a href="mailto:mephisto_9000@hotmail.com">mephisto_9000@hotmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">



<div><div dir="ltr">
<font size="2" face="Tahoma">Hello everyone,</font><div><font face="Tahoma" size="2"><br></font></div><div><font size="2" face="Tahoma">I'm currently</font><font size="2" face="Tahoma"> trying to port some embedded code from python 2.7 to python 3.2.</font></div>

<div><font size="2" face="Tahoma"><br></font></div><div><font size="2" face="Tahoma">The current code replicate the basic behavior of the python interpreter in an</font></div><div><font size="2" face="Tahoma">MFC application. When a command is entered in our embedded interpreter, </font></div>

<div><font size="2" face="Tahoma">we write it to a FILE* then transform this FILE* into a Python file with the api</font></div><div><font size="2" face="Tahoma">function PyFile_FromFile and assign it to python's stdin. We also assign another</font></div>

<div><font size="2" face="Tahoma">FILE* as python's stdout and stderr. We then call PyRun_InteractiveOne to execute</font></div><div><font size="2" face="Tahoma">the statement as the python interpreter normally would. Finally, we can easily retrieve</font></div>

<div><font size="2" face="Tahoma">the result of the execution from the output FILE*.</font></div><div><font size="2" face="Tahoma"><br></font></div><div><font size="2" face="Tahoma">This is currently the only approach we have found that allows us to retrieve the </font></div>

<div><font size="2" face="Tahoma">result of executing a statement exactly as the interpreter would.</font></div><div><font size="2" face="Tahoma"><br></font></div><div><font size="2" face="Tahoma">The problem is that the implementation of files has changed in python 3 and the function</font></div>

<div><font face="Tahoma" size="2">PyFile_FromFile has been removed.</font></div><div><font size="2" face="Tahoma"><br></font></div><div><font face="Tahoma" size="2">Does anyone knows a way to achieve the same thing as this function either trough the io module</font></div>

<div><font face="Tahoma" size="2">or the python/C api? Or could there be a better approach to what we are trying to achieve?</font></div><div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2">Keep in mind that we need to obtain the result of any statement, i.e. :</font></div>

<div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2">If the command is "2+2" the result should be "4", if the command is "1/0" the result should be</font></div>

<div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2">Traceback (most recent call last):</font></div><div><font face="Tahoma" size="2"><span style="white-space:pre-wrap"> </span>File "<stdin>", line 1, in <module></font></div>

<div><font face="Tahoma" size="2">ZeroDivisionError: division by zero</font></div><div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2">Thank you,</font></div>

<div><font face="Tahoma" size="2"><br></font></div><font color="#888888"><div><span style="font-family:Tahoma;font-size:10pt">F.L.</span></div>                                       </font></div></div>
<br>--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br></blockquote></div><br>