What is the function to evaluate code object returned byPyParser _SimpleParseString function?

B

Borse, Ganesh

Hi,

Thanks for this information

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?

Is it 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:[email protected]]
Sent: 15 November 2007 07:51
To: (e-mail address removed)
Subject: Re: How to use the evaluate the code object returned by PyParser_Simp leParseString function?
`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
==============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top