boost::python::列表长度

发布于 2024-12-21 09:31:00 字数 296 浏览 1 评论 0原文

有什么方法可以计算从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拔了角的鹿 2024-12-28 09:31:00

像 Python 一样,您应该使用 自由函数len()来获取长度。尝试

boost::python::len(list_of_something)

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

boost::python::len(list_of_something)
染墨丶若流云 2024-12-28 09:31:00

它被称为len,而不是length,它不是一个方法,而是一个独立的函数(Python不使用length方法,而是长度协议和 len() 函数)。

return boost::python::len(list_of_something);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文