473,395 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 3563
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Leon | last post by:
"stdout" is file object, it open mode is "w" and it have a close() fuction..... while it run close(), how to reopen it because I want to do rewrite it stdout content update
0
by: Heather Korns | last post by:
Here's a snippet of code that demonstrates my problem: result = PyRun_String ("import math", Py_file_input, pdict,pdict); result = PyRun_String ("math.sqrt(-1)", Py_file_input, pdict,pdict);...
2
by: Matthias | last post by:
Hello, I encountered a strange problem today. I try to do this: Log("Marker 1"); Py_XDECREF( PyRun_String( "print 'Hi!'", Py_single_input, Dict, Dict) ); Log("Marker 2"); The output looks...
9
by: Santtu Nyrhinen | last post by:
Hi, Let say that I have a function like void writeHello() { printf("Hello"); } Now I need to make an automated test fot that function. The test function returns 1 for successful and 0 for...
1
by: joeedh | last post by:
Hi I'm getting extremely odd behavior. First of all, why isn't PyEval_EvalCode documented anywhere? Anyway, I'm working on blender's python integration (it embeds python, as opposed to python...
5
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post by:
I wanna print the log to both the screen and file, so I simulatered a 'tee' class Tee(file): def __init__(self, name, mode): file.__init__(self, name, mode) self.stdout = sys.stdout...
0
by: stuart.tett | last post by:
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...
4
by: Stuart | last post by:
I've written my own python modules with the C API, called dlfl. I've now embedded a python interpreter into my Qt application. I am able to execute multiline/singleline blocks and it has no...
5
by: Joakim Hove | last post by:
Hello, I have written a program in C; this programs uses an external proprietary library. When calling a certain function in the external library, the particular function writes a message to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.