Hello everyone,
I'm currently trying to port some embedded code from python 2.7 to python 3.2.
The current code replicate the basic behavior of the python interpreter in 
anMFC application. When a command is entered in our embedded interpreter, we 
write it to a FILE* then transform this FILE* into a Python file with the 
apifunction PyFile_FromFile and assign it to python's stdin. We also assign 
anotherFILE* as python's stdout and stderr. We then call PyRun_InteractiveOne 
to executethe statement as the python interpreter normally would. Finally, we 
can easily retrievethe result of the execution from the output FILE*.
This is currently the only approach we have found that allows us to retrieve 
the result of executing a statement exactly as the interpreter would.
The problem is that the implementation of files has changed in python 3 and the 
functionPyFile_FromFile has been removed.
Does anyone knows a way to achieve the same thing as this function either 
trough the io moduleor the python/C api? Or could there be a better approach to 
what we are trying to achieve?
Keep in mind that we need to obtain the result of any statement, i.e. :
If the command is "2+2" the result should be "4", if the command is "1/0" the 
result should be
Traceback (most recent call last):      File "<stdin>", line 1, in 
<module>ZeroDivisionError: division by zero

Thank you,
F.L.                                      
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to