[Python-Dev] PyEval_EvalCode()
Guido van Rossum
guido@python.org
Thu, 17 Oct 2002 13:29:00 -0400
> > > PyEval_EvalCode()
> > > This prototype is not available when including "Python.h" (Using v2.1.3)
> > > Why did you exclude it from the "official" API prototypes?
> > Because it's unlikely that someone writing a Python extension would
> > ever have a need for it.
>
> Sure?
> I'd like to use it in a program that embeds a Python interpreter.
> The code snippets get compiled and checked by that function and can be
> called as a code object afterwards.
>
> > > Isn't that PyEval_EvalCode() the regular API function to run
> > > CodeObjects from Py_CompileString() ?
> > Probably -- I've never used it this way.
>
> At least a solution like that is described in the lastest "Programming
> Python" bible by Mark Lutz.
> (covering Python 2)
>
> > But why aren't you using
> > PyRun_String()?
>
> Speed, efficiency.
> If the code get's executed quite often (i. e. multiple times a second)
> it's worth precompiling (and maybe optimizing by Py_OptimizeFlag = 1),
> or? PyRun_String() will compile and check _every_ time - wasting a lot
> of resources.
Then feel free to import eval.h.
--Guido van Rossum (home page: http://www.python.org/~guido/)