Reputation: 1125
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?
Upvotes: 0
Views: 628
Reputation: 136266
tuple
is an immutable data structure in Python, unlike list
.
Upvotes: 0