Is PyRun_String() broken?

David Gravereaux davygrvy at pobox.com
Fri Jun 1 22:13:59 EDT 2001


All I get back from it in the PyObject* is an exception code that says 'None'.

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?


This is a central theme in other interpreted languages such as Tcl:

Tcl_Interp *interp;
int code;

interp = Tcl_CreateInterp();
code = Tcl_Eval(interp, "proc foo {} {}; expr {rand()}");
if (code == TCL_OK) {
  printf("the random number is %s", interp->result);
} else {
  printf("We bombed with %s", interp->result);
}

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?

A stumped Tcl coder trying to embed python,
--
David Gravereaux <davygrvy at pobox.com>



More information about the Python-list mailing list