bytecode & embedding

Michael P. Reilly arcege at shore.net
Thu Jul 15 10:14:12 EDT 1999


Jens Calisti <Jens.Calisti at eiskonzept.com> wrote:
: Hi all,

: I am new to python so maybe someone can answer me this :

: Is it possbile to exeute python-compiled-bytecode from a c-programm with
: embedded python ?? (eval,exec ?)

I'm not sure how "supported" this is in Python 1.6 and beyond, but you
need to include <compile.h> and <eval.h> (after <Python.h>).

  #include <Python.h>
  #include <compile.h>
  #include <eval.h>

  ...

    PyObject *globals, *locals, *result;
    PyCodeObject *bytecode;

    result = PyEval_EvalCode(bytecode, globals, locals);

The globals and locals should be dictionaries (possibly taken from
PyModule_GetDict()).

  -Arcege




More information about the Python-list mailing list