Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BOOST_ALL_NO_LIB
- #include <boost/python.hpp>
- #include <iostream>
- #include <string>
- namespace bp = boost::python;
- void module_function()
- {
- bp::object module = bp::import("my_module");
- std::string value = bp::extract<std::string>(module.attr("my_attribute"));
- std::cout << value << "\n";
- }
- BOOST_PYTHON_MODULE(my_module)
- {
- bp::def("module_function", &module_function);
- bp::scope().attr("my_attribute") = "foo";
- }
- int main()
- {
- try {
- Py_Initialize();
- initmy_module();
- // Call the function...
- bp::object module = bp::import("my_module");
- bp::object fn = module.attr("module_function");
- fn();
- } catch (bp::error_already_set) {
- PyErr_Print();
- }
- Py_Finalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement