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

Discussion in 'Python' started by Borse, Ganesh, Nov 15, 2007.

  1. 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:]
    Sent: 15 November 2007 07:51
    To:
    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 <> 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
    ==============================================================================
     
    Borse, Ganesh, Nov 15, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. opistobranchia
    Replies:
    1
    Views:
    334
    Larry I Smith
    Aug 14, 2005
  2. Ajit Goel
    Replies:
    0
    Views:
    434
    Ajit Goel
    Apr 16, 2007
  3. Borse, Ganesh
    Replies:
    0
    Views:
    297
    Borse, Ganesh
    Nov 14, 2007
  4. Replies:
    1
    Views:
    122
  5. Justin Ezequiel
    Replies:
    4
    Views:
    68
    Gregory Ewing
    Apr 26, 2014
Loading...

Share This Page