I maked this code and it does not work
#include <boost/python.hpp>
namespace bp = boost::python;
int main(int argc, char **argv) {
bp::list points;
int one = 1;
int two = 2;
int three = 3;
points.append(one); #crach!!
points.append(two);
points.append(three);
return 0;}
which is the reason why "append" does not accept integers and directly which would be the correct way?
edited
the solution is this:
#include <boost/python.hpp>
namespace bp = boost::python;
int main(int argc, char **argv) {
Py_Initialize(); //this part
bp::list points;
int one = 1;
int two = 2;
int three = 3;
points.append(one); #crach!!
points.append(two);
points.append(three);
Py_Finalize(); //this part
return 0;}
From the documentation, it looks like a template method. So, you can try
I think you are supposed to use
boost::python::list
from within the exported module, not from a C++ program directly. The reason for this is simple:boost::python::list
is a wrapper around a Python list object and to work with it you need a Python interpreter which is not available when you try to operate on the list from yourmain
method.Here's a working example:
Compiling this module and running the
getlist
function shows that everything works as expected: