How to evaluate the code object returned by PyParser_SimplePa rseString function?
Borse, Ganesh
ganesh.borse at credit-suisse.com
Wed Nov 14 21:20:14 EST 2007
Hi,
Thanks for this information.
I would like to know few more things.
Py_CompileString takes the source code from file, isn't it?
As can be seen from the syntax of this function: PyObject* Py_CompileString(char *str, char *filename, int start)
I want to parse the code which is in memory - loaded from database.
In that case, may I know, how to use the Py_CompileString?
If it is mandatory to read from file for this function?
Reading from file increases startup time of my application.
So, I was thinking of using PyParser_SimpleParseString, which takes the code to be parsed in the "char*" format. Quit suitable to my need.
Can I use the output of the function PyParser_SimpleParseString as input to PyEval_EvalCode?
Please guide.
Thanks in advance for your time & guidance.
Warm Regards,
Ganesh
-----Original Message-----
From: Gabriel Genellina [mailto:gagsl-py2 at yahoo.com.ar]
Sent: 15 November 2007 07:51
To: python-list at python.org
Subject: Re: How to use the evaluate the code object returned by PyParser_Simp leParseString function?
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
==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer:
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================
More information about the Python-list
mailing list