Submodules in dynamic modules?
Martin Sjögren
martin at strakt.com
Fri Jul 27 03:25:27 EDT 2001
On Thu, Jul 26, 2001 at 11:39:33AM -0400, Steven D. Majewski wrote:
> > I'm not sure we're talking about the same thing here. I don't want to
> > import other Python modules, I want to have several submodules in my one C
> > library file (foomodule.so on unix). I guess I COULD have several .so
> > files and import them like you do here, but that would be unnecessarily
> > complicated!
>
> No -- these are all in one dynamic lib: Carbonmodule.so.
> On "classic" MacOS, they were all separate libs.
> ( PPC MacOS followed AIX in having explicit import and export files
> so it was easy to say where exactly other symbols would be resolved.)
> On OSX, I could not figure out how to get them to link
> separately without either multiply defined or undefined symbols,
> so all of the Carbon toolbox modules were linked into a single
> dynamic lib.
>
> This *sounds* like what you're asking for, is it?
Definitely. Hmm. So what does initWin() do? Do you do several InitModule()
calls or what?
*confused*
This seems to work:
void
initfoo(void) {
PyObject *foo = Py_InitModule("foo", emptylist);
PyObject *bar = Py_InitModule("bar", emptylist);
PyModule_AddObject(foo, "bar", bar);
}
But then:
>>> import foo
>>> foo
<module 'foo' from 'foomodule.so'>
>>> foo.bar
<module 'bar' (built-in)>
Isn't this a bit...weird?
Hmm, on second thought, that's what my solution yields too :-)
Grateful for comments
Martin
--
Martin Sjögren
martin at strakt.com ICQ : 41245059
Phone: +46 (0)31 405242 Cell: +46 (0)739 169191
GPG key: http://www.strakt.com/~martin/gpg.html
More information about the Python-list
mailing list