...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Exposes a mechanism for importing python modules.
object import(str name);
Imports the module named by name.
An instance of object which holds a reference to the imported module.
The following example demonstrates the use of import to access a function in python, and later call it from within C++.
#include <iostream> #include <string> using namespace boost::python; void print_python_version() { // Load the sys module. object sys = import("sys"); // Extract the python version. std::string version = extract<std::string>(sys.attr("version")); std::cout << version << std::endl; }