471,350 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

PyRun_String with Py_single_input to stdout?

I'm using PyRun_String with Py_single_input for a python interpreter
embedded in my application. I'm using Py_single_input. Py_single input
is what I want, but it seems to output to stdout. Before when I was
using Py_eval_input I was able to grab the result so I could print it
in a text box:

PyObject *resultObject = PyObject_Str( rstring );
if( resultObject != NULL ) {
char *string = PyString_AsString( resultObject );
}

But Py_eval_input is only for isolated evaluation, not what I want.
Py_single_input gives "None" for the string.

I wrote a class that redirects std::cout, but this doesn't work for
this, I'm guessing because it uses printf to stdout, not cout.

Anyone know how I can get the string so I can print it in a text box.

Jun 18 '07 #1
2 3383
En Mon, 18 Jun 2007 01:45:38 -0300, st*********@gmail.com
<st*********@gmail.comescribió:
I'm using PyRun_String with Py_single_input for a python interpreter
embedded in my application. I'm using Py_single_input. Py_single input
is what I want, but it seems to output to stdout. Before when I was
using Py_eval_input I was able to grab the result so I could print it
in a text box:

PyObject *resultObject = PyObject_Str( rstring );
if( resultObject != NULL ) {
char *string = PyString_AsString( resultObject );
}

But Py_eval_input is only for isolated evaluation, not what I want.
Py_single_input gives "None" for the string.
Maybe because it actually returns None?
I wrote a class that redirects std::cout, but this doesn't work for
this, I'm guessing because it uses printf to stdout, not cout.

Anyone know how I can get the string so I can print it in a text box.
From your description this should be working... try posting some more code
showing how you call PyRun_String and how you process the result...

--
Gabriel Genellina

Jun 18 '07 #2
I found a solution using sys.displayhook here:
http://groups.google.com/group/comp....0f930e7ac5ebb2

On Jun 18, 4:24 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Mon, 18 Jun 2007 01:45:38 -0300, stuart.t...@gmail.com
<stuart.t...@gmail.comescribió:
I'm using PyRun_String with Py_single_input for a python interpreter
embedded in my application. I'm using Py_single_input. Py_single input
is what I want, but it seems to output to stdout. Before when I was
using Py_eval_input I was able to grab the result so I could print it
in a text box:
PyObject *resultObject = PyObject_Str( rstring );
if( resultObject != NULL ) {
char *string = PyString_AsString( resultObject );
}
But Py_eval_input is only for isolated evaluation, not what I want.
Py_single_input gives "None" for the string.

Maybe because it actually returns None?
No it doesn't. I know the function returns something because when I
used Py_eval_input, it returned the correct output. The only
difference is thate Py_string_input outputs using sys.write (stdout)
>
I wrote a class that redirects std::cout, but this doesn't work for
this, I'm guessing because it uses printf to stdout, not cout.
Anyone know how I can get the string so I can print it in a text box.

From your description this should be working... try posting some more code
showing how you call PyRun_String and how you process the result...

--
Gabriel Genellina

Jun 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Leon | last post: by
2 posts views Thread by Matthias | last post: by
9 posts views Thread by Santtu Nyrhinen | last post: by
5 posts views Thread by =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post: by
reply views Thread by stuart.tett | last post: by
4 posts views Thread by Stuart | last post: by
5 posts views Thread by Joakim Hove | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.