Entry
How do I invoke Python code from C/C++?
Jun 21st, 2002 07:13
Michael Chermside,
To invoke Python code from C or C++, you need to embed the Python
interpreter into your C program. This is actually not as extreme an idea
as you might think... Python consists of a fairly large but well-written
base of extremely portable and very well-tested C code. It is also
designed to easily embedded.
There are several reasons you would want to embed Python in a C/C++
perogram. One is simply that you might want to call an existing Python
library, but this is actually not a very likely case -- usually, you
would simply use Python as the controlling language in a case like this
(thus invoking C routines from Python instead!). But there are many
large applications which would benefit from including a scripting
language. Rather than inventing your own scripting language (and
probably finding it to be much harder than you expect), why not include
the powerful and well-designed Python language?
The official documentation on how to perform this feat can be found at
(http://www.python.org/doc/current/ext/ext.html).