简体   繁体   中英

Append element to boost::python::tuple

I'm trying to remove the second element from a boost::python::tuple object. The tuple from which I want to remove the second element is the list of arguments passed to a Python function call.

To remove the element I do like this:

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;

    ...
}

I think that the problem is that boost::python::tuple doesn't add the element, but it created a new tuple with the first and second slices as elements.

How can I solve this?

tuple是Python中的不变数据结构,与list不同。

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