]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/python/doc/reference/import.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / python / doc / reference / import.qbk
CommitLineData
7c673cae
FG
1[section boost/python/import.hpp]
2[section Introduction]
3Exposes a mechanism for importing python modules.
4[endsect]
5[section Function `import`]
6``object import(str name);``
7[variablelist
8[[Effects][Imports the module named by name.]]
9[[Returns][An instance of object which holds a reference to the imported module.]]
10]
11[endsect]
12[section Examples]
13The following example demonstrates the use of import to access a function in python, and later call it from within C++.
14``
15#include <iostream>
16#include <string>
17
18using namespace boost::python;
19
20void print_python_version()
21{
22 // Load the sys module.
23 object sys = import("sys");
24
25 // Extract the python version.
26 std::string version = extract<std::string>(sys.attr("version"));
27 std::cout << version << std::endl;
28}
29``
30[endsect]
31[endsect]