Boost::Python: List

Converting to and from a python lists is easy. If you are after a quick and dirty way see the page about pointer conversion.

This is faster but requires more work since you might need to provide a wrapper for your functions. If you just need the function to be used by python this is the better way. Same goes for returning lists.

Importing
 void getList(boost::python::list* list){ int n = boost::python::extract (list->attr("__len__")); for ( int i = 0; i < n; i++ ){ int val = (boost::python::extract ((*list)[i])); } }

I think the code basicly explains itself. First we get the number of elements in the list by accessing __len__ from the python list. Secondly we just access one element at a time and retrieves the value.