Printing returned object in embedded app
Michael P. Reilly
arcege at shore.net
Fri Jul 9 21:40:18 EDT 1999
Conrad Steenberg <conrad at srl.caltech.edu> wrote:
: I'm trying to construct an interactive front-end for Python, using GTK.
: My C program passes strings to PyRun_String, and obtains the returned object.
: Now in the normal interactive Python on a terminal, a command like
: 1+1
: would print out the value, but using my method it does not. Using
: print(1+1) works like a charm. However, when I try to have the returned object
: printed using eg.
: PyObject_CallMethod(object,"print","")
: I get an error, "AttributeError: print". Can anybody tell me what I'm doing
: wrong? Or how to get the result printed automatically like in interactive
: Python?
Try:
PyObject_Print(object, stdout, Py_PRINT_RAW);
The first argument is the object to be printed, the second is the FILE
* to print to and the last is a flag (the only flag for now is
Py_PRINT_RAW). It only outputs the object, no leading or trailing
whitespace.
Also, you could run "print object" from PyRun_SimpleString.
-Arcege
More information about the Python-list
mailing list