HOWTO : Py_CompileString !?!?!

Luc acid_til at
Thu Jan 30 15:54:56 CET 2003

Jp Calderone wrote:
> On Wed, Jan 29, 2003 at 02:43:38PM -0500, Luc wrote:
>>Hello fellow python user :)
>>I'm quite new to this so please be kind to my newbie question !!!
>>I'm trying to embed python in my C++ application. I have a python source 
>>file names and what I want to do is first try to compile it to 
>>see if any syntax error or import error occurs.  I tried to use 
>>Py_CompileString but it seems not to work. I added a syntax error and it 
>>still report no error. Now I just thought that because it's interpreted, 
>>does it mean that the error is caught until the script is actually run 
>>??? If so, is there any method that I could use to detect such error 
>>without resorting to running the script ???
>   It's impossible to say what's going wrong without seeing at least a
> minimal sample of your code.  Can you post the shortest snippet possible
> that completely duplicates the behavior you believe to be incorrect?  If so,
> we can look at it and point out in particular where your expectations don't
> coincide with the actual behavior.
>   Jp

Of course,

Here is the script in question :

import FOMath
#FOMath has a method called PointValue()
def test():
	print FOMath.PointdddValue()


This should't compile because a syntax error is present...

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(), "<>", Py_file_input);

That's it. It's the way I tought was proper. Might be wrong, that's why 
I posted in this group :)

Cheers, Luc.

More information about the Python-list mailing list