How to use the evaluate the code object returned by PyParser_Simp leParseString function?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Nov 14 18:50:46 EST 2007


En Wed, 14 Nov 2007 06:48:41 -0300, Borse, Ganesh  
<ganesh.borse at credit-suisse.com> escribió:

> `struct _node* PyParser_SimpleParseString(char *str, int start)'
>      Parse Python source code from STR using the start token START. The  
> result can be used to create a code object which can be evaluated  
> efficiently.
>      This is useful if a code fragment must be evaluated many times.
>
> I have exactly same requirement. I have dynamic expressions loaded from  
> database at startup in my C++ application.
> I want to parse these expressions at startup & keep the parsed  
> (compiled) code in memory of this application.
> Then at runtime, I want to evaluate all this parsed code. This has to be  
> very efficient.

parsed != compiled. Use Py_CompileString instead. The resulting code  
object may be executed with PyEval_EvalCode.

BTW, instead of looking at some random web site, it's better to read the  
official documentation at http://docs.python.org. You should have a copy  
of it in the Doc subdirectory inside your Python installation.

-- 
Gabriel Genellina




More information about the Python-list mailing list