[英]Append element to boost::python::tuple
我正在嘗試從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
沒有添加元素,但是它創建了一個以第一和第二個切片為元素的新元組。
我該如何解決?
tuple
是Python中的不變數據結構,與list
不同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.