views:

69

answers:

2

Hello

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)

Thanks, Elias

A: 

I can't give you a full answer, but I think I can give you a place to start. Python provides a built-in module called imp which provides access to import internals. It includes a function load_module() which lets you pass in a path. This is implemented in Python/import.c; just search for imp_load_module.

inklesspen
A: 

Eventually, I ended up using the load_source from imp module:

s.sprintf( 
  "import imp\n" 
  "imp.load_source('%s', r'%s')", modname, script_path); 
PyRun_SimpleString(s.c_str());

I think it is the most feasible solution. Other suggestions are welcome.

lallous