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

grbgooglefan ganeshborse at gmail.com
Thu Nov 22 02:17:37 EST 2007


On Nov 16, 7:11 am, "Terry Reedy" <tjre... at udel.edu> wrote:
> "Borse, Ganesh" <ganesh.bo... at credit-suisse.com> wrote in message
>
> news:F444CAE5E62A714C9F45AA292785BED327C3BF57 at esng11p33001.sg.csfb.com...
> | Py_CompileString takes the sourcecodefrom file, isn't it?
>
> No.
>
> | As can be seen from the syntax of thisfunction: "PyObject*
> Py_CompileString(char *str, char *filename, int start)"
>
> I am rather sure that the filename param is the same as for the
> Python-level builtinfunctioncompile:
>       compile( string, filename, kind[, flags[, dont_inherit]])
>
> Compile the string into acodeobject.Codeobjects can be executed by an
> exec statement or evaluated by acallto eval(). The filename argument
> should give the file from which thecodewas read; pass some recognizable
> value if it wasn't read from a file ('<string>' is commonly used).
>
> The filename is used for exception traceback messages.

Hi,
I want to put this code in a function & call it.
I am now facing a problem that, I am able to compile a function using
Py_CompileString. That generates a "*definition*" of that function.
I am stuck at a road block & not able to execute this function
definition which is part of "*codeObject*" returned by
Py_CompileString.

What should I do to transform this 'code' object to 'callable' or
'function' object, so that I can call it?

Please help.
Regards.



More information about the Python-list mailing list