I was wondering if anyone has some good examples of running python functions and scripts within C++ using the Python C API. I can't seem to understand the ways of the Python C API, and was expecting something more similar to the Lua C API.

The real question is "What are some ways to use python in C++ programs, such as calling python functions from C++ and calling C++ functions from python?"

Sorry if I worded this a little awkward, I am not the most experienced poster.

> I was wondering if anyone has some good examples of running python functions and scripts
> within C++ using the Python C API.

Python documentation has a simple example: http://docs.python.org/extending/embedding.html
Another simple example: http://code.google.com/p/kanghtta/source/browse/trunk/Python/Demo/embed/demo.c?r=16
Somewhat more involved: http://www.codeproject.com/KB/cpp/embedpython_1.aspx


> What are some ways to use python in C++ programs,
> such as calling python functions from C++ and calling C++ functions from python?

Instead of using the somewhat low level Python C API, you could use a library that wraps it and provides more functionality. For example:
http://www.boost.org/doc/libs/1_48_0/libs/python/doc/
http://www.swig.org/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.