Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost/Python: How can I use/convert extracted objects?

Suppose:

using namespace boost::python;
void myClass::test(numeric::array& arrayParam) {
    const tuple &shape = extract<tuple>(arrayParam.attr("shape"));
}

I would like to transform it to an int and print for example. I tried int x = shape[0]; but it gives me a "cannot convert ‘boost::python::api::const_object_item’ to ‘int’ in initialization" message.

like image 481
gaben Avatar asked Mar 26 '11 05:03

gaben


1 Answers

shape[0] gives you a Python object. To convert it to an int or another C++ type, you need to extract the value:

int x = extract<int>(shape[0]);
like image 83
interjay Avatar answered Sep 18 '22 11:09

interjay