简体   繁体   中英

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.

Simple Example in 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++?

EDIT:

This is my setup.py file.

#!/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"]
        )
    ])

It seems you're using boost-python. Then should use boost::python::tuple, not std::tuple. See the examples on this page .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM