1 [section boost/python/import.hpp]
3 Exposes a mechanism for importing python modules.
5 [section Function `import`]
6 ``object import(str name);``
8 [[Effects][Imports the module named by name.]]
9 [[Returns][An instance of object which holds a reference to the imported module.]]
13 The following example demonstrates the use of import to access a function in python, and later call it from within C++.
18 using namespace boost::python;
20 void print_python_version()
22 // Load the sys module.
23 object sys = import("sys");
25 // Extract the python version.
26 std::string version = extract<std::string>(sys.attr("version"));
27 std::cout << version << std::endl;