Is PyRun_String() broken?

Martin von Loewis loewis at informatik.hu-berlin.de
Tue Jun 5 04:30:13 EDT 2001


David Gravereaux <davygrvy at pobox.com> writes:

> I've tried using Py_single_input for the start token, but the result of the
> operation is sent to stdout.  How is it possible to eval code and get the result
> back?  As far as I've able to RTFM and "use the source luke" is to determine
> that eval_code2() when coming back out of the eval falls into the POP_TOP case
> and does Py_DECREF(v) on the result to destroy it.
> 
> I WANT IT!  WHERE'D IT GO?

If you want the result of some computation, that computation better be
an expression; statements don't have a result. So you should use
Py_eval_input.

> If all that PyRun_String() returns is "exception or not", where/how is it
> possible to get the last result of the operation?  Is it true that POP_TOP in
> eval_code2() of ceval.c discards the object before returning?  How can I not pop
> the top, and grab the result then Py_DECREF it after I'm done?

You cannot. If you have a Py_file_input that has "computes some
value", that file input should either assign to some variable, or be a
function that you can call so that it returns a result.

Why do you want the result of the last expression statement, anyway?

Regards,
Martin




More information about the Python-list mailing list