Boost :: python :: list length

Is there a way to calculate the length of a list passed from python to C ++? I want to do something like this, but the length method (or something similar) is missing from the list of classes:

 class Awesome{ public: void awesomeMethod(const boost::python::list& list_of_something){ list_of_something.length() // suprisingly there no such method } }; 
+6
source share
2 answers

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

 boost::python::len(list_of_something) 
+16
source

It is called len , not length , and it is not a method, but an independent function (Python does not use the length methods, but the length protocol and len() ).

 return boost::python::len(list_of_something); 
+2
source

Source: https://habr.com/ru/post/903804/


All Articles