0

我正在尝试从boost::python::tuple对象中删除第二个元素。我要从中删除第二个元素的元组是传递给 Python 函数调用的参数列表。

要删除我这样做的元素:

BPY::object CallMethod(BPY::tuple args, BPY::dict kwargs)
{
    ...

    // args is my original tuple from which I want to remove the second element

    boost::python::api::object_slice firstSlice = args.slice(0, 1);
    boost::python::tuple newArgs = boost::python::extract<boost::python::tuple>(firstSlice);

    if(boost::python::len(args) > 2)
    {
        boost::python::api::object_slice secondSlice = args.slice(2, boost::python::len(args));
        boost::python::tuple secondSliceArgs = boost::python::extract<boost::python::tuple>(secondSlice);

        newArgs = boost::python::make_tuple(newArgs, secondSliceArgs);
    }

    args = newArgs;

    ...
}

我认为问题在于boost::python::tuple没有添加元素,但它创建了一个新的元组,其中第一个和第二个切片作为元素。

我该如何解决这个问题?

4

1 回答 1

0

tuple是 Python 中的不可变数据结构,与list.

于 2016-05-12T09:23:30.257 回答