我正在尝试从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没有添加元素,但它创建了一个新的元组,其中第一个和第二个切片作为元素。
我该如何解决这个问题呢?
发布于 2016-05-12 17:23:30
与list不同,tuple是Python语言中的不可变数据结构。
https://stackoverflow.com/questions/37180878
复制相似问题