[Python-Dev] PyEval_EvalCode() (original) (raw)

Guido van Rossum guido@python.org
Thu, 17 Oct 2002 13:29:00 -0400


> > PyEvalEvalCode() > > 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 PyEvalEvalCode() the regular API function to run > > CodeObjects from PyCompileString() ? > 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 > PyRunString()? Speed, efficiency. If the code get's executed quite often (i. e. multiple times a second) it's worth precompiling (and maybe optimizing by PyOptimizeFlag = 1), or? PyRunString() 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/)