Embedding Python in C
Stefan Behnel
stefan_ml at behnel.de
Fri Jul 19 14:32:33 EDT 2019
Jesse Ibarra schrieb am 17.07.19 um 20:39:
> My options seem rather limited, I need to make a Pipeline from
> (Smalltalk -> C -> Python) then go back (Smalltalk <- C <- Python).
> Since Smalltalk does not support Python directly I have to settle with
> the C/Python API
> (https://docs.python.org/3.6/extending/embedding.html#beyond-very-high-level-embedding-an-overview).
> Any suggestions?
First of all: don't use the C-API! :-)
Use Cython instead. It's a Python-to-C compiler that covers up all the ugly
little details of talking to Python from C (importing a module is just
"import module", and it even adapts to different Python versions
automatically). You can keep writing Python code, and at the same time
trivially use external C code.
https://cython.org/
http://docs.cython.org/en/latest/src/tutorial/
For embedding Python in an external program (in case you really need to do
that and can't live with starting Python instead of Smalltalk), here's an
example:
https://github.com/cython/cython/tree/master/Demos/embed
It uses the "--embed" argument to Cython that generates a C (main) function
to start up the CPython runtime.
Stefan
More information about the Python-list
mailing list