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
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Problem with sys.path when embedding Python3 in C
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password