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

Let's pretend that:

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

I would like to convert it to int and print, for example. I tried int x = shape[0]; but it gives me "impossible to convert" boost :: python :: api :: const_object_item into the message "int in initialization".

+4
source share
1 answer

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

 int x = extract<int>(shape[0]); 
+8
source

Source: https://habr.com/ru/post/1345309/


All Articles