Problem with sys.path when embedding Python3 in C

K

Krister Svanlund

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.com/805BSY8f
You only need a file in the same directory called stuff.py containing
a function def for a function called do_stuff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top