Embedding? file_input and eval_input

Gordon McMillan gmcm at hypernet.com
Fri Aug 11 20:26:58 EDT 2000


James Spears wrote:

>I am embedding Python in a tool and would like the user to be able to
>issue Python command and evaluate 
>expressions. 

I hope you have very friendly, very well-behaved users.

>here is the problem:
>
>PyRun_String with a statement and single_input returns PyNone
>PyRun_String with a expression and single_input *PRINTS the result* and
>returns PyNone
>
>PyRun_String with a statement and file_input returns PyNone
>PyRun_String with a expression and file_input returns PyNone
>
>PyRun_String with a statement and eval_input returns NULL indicating an
>error.
>PyRun_String with a expression and eval_input returns PyObject* with the
>expected value.

Where is the problem? Use eval_input, if it returns NULL, it's probably a 
statement so use single_input. For better or worse, evaluation and 
execution are fundamentally different operations in Python.

- Gordon



More information about the Python-list mailing list