boost::python::列表长度
有什么方法可以计算从 python 传递到 C++ 的列表长度吗?我想做做 像这样的东西,但列表类缺少 length
(或任何类似的)方法:
class Awesome{
public:
void awesomeMethod(const boost::python::list& list_of_something){
list_of_something.length() // suprisingly there's no such method
}
};
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
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像 Python 一样,您应该使用 自由函数
len()
来获取长度。尝试Like Python, you should use the free function
len()
to get the length. Try它被称为
len
,而不是length
,它不是一个方法,而是一个独立的函数(Python不使用length
方法,而是长度协议和 len() 函数)。It's called
len
, notlength
, and it's not a method but a free-standing function (Python does not uselength
methods, but length protocol andlen()
function).