[C++-sig] [boost python] : how to pass a tuple of lists from python to C++

stefan stefan at seefeld.name
Fri Feb 7 16:43:10 EST 2020


On 2020-02-07 4:06 p.m., HOUSSEN Franck wrote:
> With boost python, how to pass a tuple of lists from python to C++ ? 
> Code attached : line 12 crashes ?! Googling but no fix for now.

You are referring to this line:

   np::ndarray lsInt = boost::python::extract<np::ndarray>(t[0]);

Note that this line is actually doing two things:

1) it creates a boost::python::extract<np::ndarray> object

2) it calls conversion operator on it to convert to np::ndarray

Note that the conversion may fail (for example if the object doesn't 
contain an object of that type). In case of doubt, you may want to call 
extract::check() to see whether it's actually valid.

See 
https://www.boost.org/doc/libs/1_72_0/libs/python/doc/html/reference/to_from_python_type_conversion.html#to_from_python_type_conversion.boost_python_extract_hpp.class_template_extract 
for details.



Stefan

--

       ...ich hab' noch einen Koffer in Berlin...
     

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20200207/10beef35/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.png
Type: image/png
Size: 1478 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20200207/10beef35/attachment.png>


More information about the Cplusplus-sig mailing list