Creating a "package" using C extensions?
jkraska at san.rr.com
Mon Dec 10 19:31:02 CET 2001
>IF you figure out how to do this, I'd love to see an example. It owuld
>be prettyhandy for me as well. Maybe even a cookbook entry?
I've figured it out. It's not hard at all, however there is a small
amount of repetitive labor involved. Here is the init method for
my "package" that I'm developing:
void _declspec(dllexport) initlrammp()
PyObject* m = Py_InitModule3("lrammp", LrammpModuleMethods, LrammpModuleDocs );
PyObject* d = PyModule_GetDict(m);
PyDict_SetItemString(d, "simulator", __LRAMMP__SimulatorModuleInit());
PyDict_SetItemString(d, "agent", __LRAMMP__AgentModuleInit());
Note the specific mutations on the "lrammp" module's dictionary at
init time. I am adding modules, as defined in the __LRAMMP__* forms
directly to the dictionary. These are taken from seperate source files
that have "pseudo init" methods of their own. They're not _declspecd
and aren't intended to invoked directly by Python.
This seems to work in testing my .py file. For example, the following
seems to work as expected:
from lrammp import simulator
from lrammp import agent
Likewise what is imported appears to be a proper module.
This functionality seems to fit the bill for me.
Not having to produce a couple dozen .dlls is a relief. :)
More information about the Python-list