Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

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

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


lallous at lgwm

Nov 25, 2009, 12:51 AM

Post #1 of 2 (156 views)
Permalink
How to import a file by its full path using C api?

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
--
http://mail.python.org/mailman/listinfo/python-list


lallous at lgwm

Nov 25, 2009, 6:27 AM

Post #2 of 2 (146 views)
Permalink
Re: How to import a file by its full path using C api? [In reply to]

Looks like one way to do that is to use something like:

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

Unless someone has a better suggestion.

Regards,
Elias
"lallous" <lallous [at] lgwm> wrote in message news:heir4g$ohv$1 [at] aioe
> 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
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.