Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::python::list length

Is there any way to calculate length of list passed from python to C++? I want do do something like this, but list class lacks length (or anything similar) method:

class Awesome{
  public:
    void awesomeMethod(const boost::python::list& list_of_something){
      list_of_something.length() // suprisingly there's no such method
    } 
};
like image 902
KCH Avatar asked Dec 14 '11 21:12

KCH


2 Answers

Like Python, you should use the free function len() to get the length. Try

boost::python::len(list_of_something)
like image 65
kennytm Avatar answered Sep 19 '22 16:09

kennytm


It's called len, not length, and it's not a method but a free-standing function (Python does not use length methods, but length protocol and len() function).

return boost::python::len(list_of_something);
like image 29
Cat Plus Plus Avatar answered Sep 18 '22 16:09

Cat Plus Plus