12345678910111213141516171819202122232425262728293031 |
- [section boost/python/import.hpp]
- [section Introduction]
- Exposes a mechanism for importing python modules.
- [endsect]
- [section Function `import`]
- ``object import(str name);``
- [variablelist
- [[Effects][Imports the module named by name.]]
- [[Returns][An instance of object which holds a reference to the imported module.]]
- ]
- [endsect]
- [section Examples]
- 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;
- }
- ``
- [endsect]
- [endsect]
|