<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
<font class="Apple-style-span" size="2" face="Tahoma">Hello everyone,</font><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" size="2" face="Tahoma">I'm currently</font><font class="Apple-style-span" size="2" face="Tahoma"> trying to port some embedded code from python 2.7 to python 3.2.</font></div><div><font class="Apple-style-span" size="2" face="Tahoma"><br></font></div><div><font class="Apple-style-span" size="2" face="Tahoma">The current code replicate the basic behavior of the python interpreter in an</font></div><div><font class="Apple-style-span" size="2" face="Tahoma">MFC application. When a command is entered in our embedded interpreter, </font></div><div><font class="Apple-style-span" 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 class="Apple-style-span" size="2" face="Tahoma">function PyFile_FromFile and assign it to python's stdin. We also assign another</font></div><div><font class="Apple-style-span" size="2" face="Tahoma">FILE* as python's stdout and stderr. We then call PyRun_InteractiveOne to execute</font></div><div><font class="Apple-style-span" size="2" face="Tahoma">the statement as the python interpreter normally would. Finally, we can easily retrieve</font></div><div><font class="Apple-style-span" size="2" face="Tahoma">the result of the execution from the output FILE*.</font></div><div><font class="Apple-style-span" size="2" face="Tahoma"><br></font></div><div><font class="Apple-style-span" size="2" face="Tahoma">This is currently the only approach we have found that allows us to retrieve the </font></div><div><font class="Apple-style-span" size="2" face="Tahoma">result of executing a statement exactly as the interpreter would.</font></div><div><font class="Apple-style-span" size="2" face="Tahoma"><br></font></div><div><font class="Apple-style-span" size="2" face="Tahoma">The problem is that the implementation of files has changed in python 3 and the function</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">PyFile_FromFile has been removed.</font></div><div><font class="Apple-style-span" size="2" face="Tahoma"><br></font></div><div><font class="Apple-style-span" 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 class="Apple-style-span" 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 class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">Keep in mind that we need to obtain the result of any statement, i.e. :</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" 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 class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">Traceback (most recent call last):</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><span class="Apple-tab-span" style="white-space:pre">      </span>File "<stdin>", line 1, in <module></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">ZeroDivisionError: division by zero</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">Thank you,</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><span class="Apple-style-span" style="font-family: Tahoma; font-size: 10pt; ">F.L.</span></div>                                          </div></body>
</html>