mephisto_9000 at hotmail
May 8, 2012, 12:07 PM
Retrieving result from embedded execution
We are trying to implement our own interactive interpreter in our applicationusing an embedded Python interpreter.
I was wondering what would be the best way to retreive as text the result of executing Python code. The text must be exactly the same as it would be in thestandalone interpreter.
We used to do this by changing the embedded interpreter's sys.stdout and sys.stderrwith a FILE created in C++. We could then execute code using the PyRun_InteractiveOnefunction and easily retrieve the result from the FILE. The problem is, our applicationshouldn't create any files if possible.
We also tried replacing sys.stdout and sys.stderr with a custom made Python objectwhich could be more easily read from C++. We then used the function PyRun_Stringto execute the code. The problem here is that using the Py_file_input start tokendoesn't write everything we need to sys.stdout. (i.e. executing 2+2 does not write 4).It also doesn't print a traceback to sys.stderr when there is an exception. Using theother two start tokens is impossible since we need to be able to execute more than one instruction at once. We also tried using the function PyRun_SimpleString but weencounter the same problems.
We are using python 2.7.
Thank you for your time.
Also, I'm new to mailling lists, what is the proper way to reply to someone? Should Ireply directly to someone's email adress or is there a way to answer trough the server.