[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Problem with sys.path when embedding Python3 in C

Krister Svanlund

3/22/2010 9:20:00 PM

Hi, I've recently begun experimenting with embedding python and i got
a small problem.
This is my current testing code (basically all from python docs):

> int main(int argc, char *argv[])
>
> {
>
> PyObject *pModuleName, *pTestModule, *pTestFunc, *pTestResult, *pTestArgs;
>
> PyImport_AppendInittab("node", &PyInit_node);
>
> Py_Initialize();

The following line here is the ugly-hack I had to do to make it work,
nothing else I know of makes it possible to import modules from
startup directory. So my question is: Is there a prettier way to do
this?

> PyRun_SimpleString("import sys\nsys.path.append(\"\")");
>
> PyRun_SimpleString("import sys\nprint(sys.path)");
>
> pModuleName = PyUnicode_FromString("stuff");
>
> pTestModule = PyImport_Import(pModuleName);
>
> Py_DECREF(pModuleName);
>
> if (pTestModule != NULL)
>
> { ...

The whole code is here: http://pastebin.co...
You only need a file in the same directory called stuff.py containing
a function def for a function called do_stuff