Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import a file by its full path using C api?

PyObject* PyImport_ImportModule( const char *name) 

How to specify a full file path instead and a module name?

Like PyImport_SomeFunction(const char *path_to_script, const char *name).

like image 591
Elias Bachaalany Avatar asked Nov 25 '09 13:11

Elias Bachaalany


1 Answers

Another solution for cases when all *.py file are in one directory:

PySys_SetPath("path/with/python/files");
PyObject *pModule = PyImport_ImportModule("filename_without_extension");
like image 182
AlexP Avatar answered Oct 05 '22 22:10

AlexP