HOWTO : Py_CompileString !?!?!

Mark Charsley mark.charsley at REMOVE_THIS.radioscape.com
Thu Jan 30 14:07:00 EST 2003


In article <OXa_9.4120$nD1.943639 at news20.bellglobal.com>, 
acid_til at yahoo.com (Luc) wrote:

> >>I'm trying to embed python in my C++ application. I have a python 
> source >>file names test.py and what I want to do is first try to 
> compile it to >>see if any syntax error or import error occurs.

> Here is the script in question :
> 
> import FOMath
> #FOMath has a method called PointValue()
> def test():
> 	print FOMath.PointdddValue()
> 
> test()
> 
> This should't compile because a syntax error is present...

There isn't a syntax error I can see. Until you run the string, python 
doesn't know that FOMath hasn't had a function called PointdddValue added 
to it. 

Now if you left out the colon in "def test():", that _would_ be a syntax 
error, and Py_CompileString would return NULL.

> 
> The way I compile the code from C++ is done like so :
> 
> //str contains the file that just loaded...
> Py_CompileString((char*)str.c_str(), "<test.py>", Py_file_input);

That looks about right.

HTH

Mark




More information about the Python-list mailing list