Printing returned object in embedded app
Michael P. Reilly
arcege at shore.net
Mon Jul 12 12:34:30 EDT 1999
Conrad Steenberg <conrad at vanir.srl.caltech.edu> wrote:
: On 10 Jul 1999 18:24:33 GMT, Conrad Steenberg <conrad at vanir.srl.caltech.edu>
: wrote:
:>On Sat, 10 Jul 1999 01:40:18 GMT, Michael P. Reilly <arcege at shore.net> wrote:
:>>
:>>Try:
:>> PyObject_Print(object, stdout, Py_PRINT_RAW);
:>
:>Thanks!
:>
:>Conrad
:>--
: Hmmm... Sorry to reply to my own message, but it seems like PyRun_String
: returns only the Py_None object!
: How can I get the result of a calculation, say
: obj=PyRun_String ("1+1", start, globals, locals);
: which should be a numeric object?
: The behaviour I'm trying to get is the same as running python on a terminal:
: when an instruction have a printable result, I want to print it.
You should be able to wrap the code you want in something like:
char buffer[256];
char expression[] = "1+1";
sprintf(buffer, "result = (%s); print result", expression);
PyRun_String(buffer, start, globals, locals);
This would only work for expressions, but then.. you can't print the
results of statements anyways. ;)
-Arcege
More information about the Python-list
mailing list