Question

I need to build a numpy array into C++ program

bp::list py_points;
// some code ....

and in some part of the code I need to convert py_points to a PyObject * type to evaluate a python module

PyObject * point_array, * numpy, * ndarray;
numpy = PyImport_ImportModuleNoBlock("numpy");
ndarray = PyObject_GetAttrString(numpy, "array");
point_array = PyEval_CallObject(ndarray,bp::extract<PyObject *>(py_points)); //error!

the error is in this part

bp::extract<PyObject *>(py_points)

what is the correct way to convert boost python object to PyObject?

thaks a lot!

Was it helpful?

Solution

You can not extract a PyObject from boost::python::object. The object class has a member ptr() which is returning the underlaying PyObject.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top