PyRun_String

Matthias nitrogenycs at web.de
Thu Mar 9 19:48:56 CET 2006


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 like

Marker 1
Hi!
Hi!
Marker 2

Obviously Hi! is printed twice. I've extracted the above example of a more  
complex piece of code where you can clearly see that the statement is  
actually executed twice (not only printed). You can also see this with

Log("Marker 1");
Py_XDECREF( PyRun_String( "def func():\n\ti = 0\n\twhile 1:\n\t\tyield  
i\n\t\ti += 1\no=func()", Py_file_input, Dict, Dict) );
Py_XDECREF( PyRun_String( "print o.next()", Py_file_input, Dict, Dict) );
Log("Marker 2");


Here the output goes

Marker 1
0
1
Marker 2


What is the reason for this very strange behaviour? Did I do something  
wrong?

-Matthias



More information about the Python-list mailing list