Embedding and extending

Daniel Berlin dan at cgsoftware.com
Thu Feb 10 21:52:53 EST 2000

jidun at my-deja.com writes:

> I know there are some threads discussing this,
> but usually they concentrate on one or the other.
> Also all of them refer to the online python.org
> documentation which really isnt that good on
> these two topics, imho.
> Here is my understanding from those threads:
> To do both I need three 'modules':
> 1: python
> 2: the module that extends python (.dll on Win32)
> 3: my application that embeds python (.exe on
> Win32)
> Is there a way to eliminate module 2? In other
> words, can module 3 be both the app that embeds
> python and the module that has the functions
> python can call back to?
Yes, you can.
I use CXX in C++ to do this (Using the Py::ExtensionModule class)
I actually add and remove things from the modules on the fly.
> To elaborate: I know that a extend-module
> called 'mymod' needs an initmymod function that
> python calls when it imports it to get hold of
> the function table. When I embed python in my
> application, can I somehow hand over that
> function table to python so that my scripts can
> call back into my application?

If you aren't using C++, I don't remember the exact underlying Python
C api being using offhand (Mainly because i haven't seen it in a few
months :P), but that's all CXX is using at the lowest level, so it's
definitely possible.

> Thanks
> -Ron

More information about the Python-list mailing list