Calling python function from C and import questions
Gabriel Genellina
gagsl-py at yahoo.com.ar
Fri Jan 26 22:21:02 EST 2007
<sndive at gmail.com> escribió en el mensaje
news:1169844647.673719.25810 at j27g2000cwj.googlegroups.com...
> Is there a better way to make a call from C than
>
> PyRun_SimpleString("import
> foo_in_python\nfoo_in_python.bar(whatever)\n");
>
> I already imported the foo_in_python using PyImport_ImportModule
> and wonder why do I need to keep importing it every time I'm
> calling a python function in that module.
Sure. Use the reference to the module that you got from
PyImport_ImportModule; you call a method using PyObject_CallMethod or
similar.
> Does anyone know why does the import tries to load .py files before
> .pyc?
It has to be sure that the .pyc is up-to-date; the .pyc contains a magic
number and the modification time of the corresponding .py
--
Gabriel Genellina
More information about the Python-list
mailing list