Re: [exim-dev] Embedding Python

Top Pagina
Delete this message
Reply to this message
Auteur: Johannes Berg
Datum:  
Aan: Todd Lyons
CC: exim-dev
Onderwerp: Re: [exim-dev] Embedding Python
On Wed, 2013-05-01 at 12:28 -0700, Todd Lyons wrote:

> Python has a very simple initialization procedure, that part works
> with no issues. The show-stopper problem I have so far is that I'm
> giving it a script to import that is in exim's config directory
> instead of in the python search path. From the shell, I can specify
> an additional subdirectory to look in when importing modules, but I
> couldn't find a simple function in the python api to make it add a
> path to the python module loader search paths.


I had this same problem once, and did this workaround:

#define PYTHON_DIR "..."

static const char pypath[] =
"import sys\n"
"sys.path.append(\"" PYTHON_DIR "\")\n";

...

    Py_Initialize();


    m = PyImport_AddModule("__main__");
    globals = PyModule_GetDict(m);


    res = PyRun_String(pypath, Py_file_input, globals, globals);
    if (!res) {
        PyErr_Print();
        return -1;
    } else
        Py_DECREF(res);


johannes