Calling python function from C and import questions

sndive at gmail.com sndive at gmail.com
Fri Jan 26 15:50:47 EST 2007


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.

I stepped thru PyImport_ImportModule and it seems rather expensive.

I assume the module will end up in cache after PyImport_ImportModule
so that subsequent
PyRun_SimpleString("import foo_in_python\n...
is cheaper but I still have to wonder if I what I'm doing is the right
thing or there is a much simpler way of doing this.

Does anyone know why does the import tries to load .py files before
.pyc?
Thank you.




More information about the Python-list mailing list