[英]Append element to boost::python::tuple
I'm trying to remove the second element from a boost::python::tuple
object. 我正在尝试从
boost::python::tuple
对象中删除第二个元素。 The tuple from which I want to remove the second element is the list of arguments passed to a Python function call. 我要从中删除第二个元素的元组是传递给Python函数调用的参数列表。
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. 我认为问题在于
boost::python::tuple
没有添加元素,但是它创建了一个以第一和第二个切片为元素的新元组。
How can I solve this? 我该如何解决?
tuple
是Python中的不变数据结构,与list
不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.