0

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?

zeb
  • 1,105
  • 2
  • 9
  • 32
  • Silly question. I just needed to do it like this (to concatenate two tuples): `newArgs = BPY::extract(newArgs + secondSliceArgs);` – zeb May 12 '16 at 08:13

1 Answers1

0

tuple is an immutable data structure in Python, unlike list.

Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271