2016-05-12 64 views
0

我試圖從boost::python::tuple對象中移除第二個元素。我想從中刪除第二個元素的元組是傳遞給Python函數調用的參數列表。添加元素以提升:: python :: tuple

要刪除我不喜歡這樣的元素:

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不添加的元素, 但它創造了第一和第二片段作爲元素的新的元組。

我該如何解決這個問題?

+0

愚蠢的問題。我只需要這樣做(連接兩個元組):'newArgs = BPY :: extract (newArgs + secondSliceArgs);' – zeb

回答

0

tuple是Python中不可變的數據結構,與list不同。