Capturing PyRun_String stdout

Chris Moller moller at mollerware.com
Wed Jul 1 00:33:54 EDT 2015


I sent this to the wrong list a few hours ago.  I hope I've gotten it 
right this time...

=====================================================

I expect this has been asked before, but I can't find out much about it...

I'm trying to embed Python in a GTK+/C app  as a scripting language and 
I need to capture the output of PyRun_String(), PyEval_EvalCode(), or 
whatever as a char * (or wchar_t * or whatever) rather than have it go 
to stdout.

I'm using Python 3.3.2 under plain C, not C++

And, while I'm interrupting everyone's evening, another question: if I  
pass Py_single_input to PyRun_String() or 
Py_CompileString()/PyEval_EvalCode(), it accepts statements like "a=10" 
and can then properly do stuff like "print(a)".  If I use Py_eval_input 
instead, I get error messages.  In both cases, I'm using the same 
global_dict and local_dict, if that makes any difference.  What am I 
doing wrong?

Thanks,
Chris Moller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150701/ec7c7f8e/attachment.html>


More information about the Python-list mailing list