Advertisement
jsperfUnkn0wn

19Apr2012@0009GMT-main.cpp

Apr 18th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <boost/python.hpp>
  2. #include <iostream>
  3.  
  4. int main(int, char **) {
  5.   using namespace boost::python;
  6.  
  7.   Py_Initialize();
  8.  
  9.   try {
  10.     PyRun_SimpleString("result = 5 ** 2");
  11.  
  12.     object module(handle<>(borrowed(PyImport_AddModule("__main__"))));
  13.     object dictionary = module.attr("__dict__");
  14.     object result = dictionary["result"];
  15.     int result_value = extract<int>(result);
  16.  
  17.     std::cout << result_value << std::endl;
  18.  
  19.     dictionary["result"] = 20;
  20.  
  21.     PyRun_SimpleString("print result");
  22.   } catch (error_already_set) {
  23.     PyErr_Print();
  24.   }
  25.  
  26.   Py_Finalize();
  27.   return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement