[英]Python: C++ extension returning multiple values
I am writing a C++ extension for python script and want to return multiple values like what we can do in python function.我正在为 python 脚本编写一个 C++ 扩展,并希望返回多个值,就像我们在 python 函数中可以做的那样。
Simple Example in python: python中的简单示例:
def test():
return 0,0
tuple seems to be the closest answer元组似乎是最接近的答案
#include <tuple>
std::tuple<int,int> test(void){
return std::make_tuple(0,0);
}
But when I compile it, it complains that但是当我编译它时,它抱怨说
TypeError: No to_python (by-value) converter found for C++ type: std::tuple<int, int>
Anyone knows if I could return multiple values using C++?任何人都知道我是否可以使用 C++ 返回多个值?
EDIT:编辑:
This is my setup.py file.这是我的 setup.py 文件。
#!/usr/bin/env python
from distutils.core import setup
from distutils.extension import Extension
setup(name="PackageName",
ext_modules=[
Extension("foo", ["foo.cpp"],
libraries = ["boost_python"],
extra_compile_args = ["-std=c++11"]
)
])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.