Best way for add new path when embedding python into C

Christian Heimes lists at cheimes.de
Mon Sep 1 14:08:09 CEST 2008


Pau Freixes wrote:
> The best way for add new path before call PyImport_Import is adding new
> string item into sys path object ?

The same way you'd add a path in Python:


PyObject *sys_path;
PyObject *path;

sys_path = PySys_GetObject("path");
if (sys_path == NULL)
     return NULL;
path = PyString_FromString("/your/path")
if (path == NULL)
     return NULL;
if (PyList_Append(sys_path, path) < 0)
     return NULL
Py_RETURN_NONE;


Christian




More information about the Python-list mailing list