9

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
    } 
};
ildjarn
  • 62,044
  • 9
  • 127
  • 211
KCH
  • 2,794
  • 2
  • 23
  • 22

2 Answers2

22

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

boost::python::len(list_of_something)
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
2

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);
Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224