3

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!

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.