簡體   English   中英

Boost / Python:如何使用/轉換提取的對象?

[英]Boost/Python: How can I use/convert extracted objects?

假設:

using namespace boost::python;
void myClass::test(numeric::array& arrayParam) {
    const tuple &shape = extract<tuple>(arrayParam.attr("shape"));
}

我想將它轉換為int並打印例如。 我試過int x = shape[0]; 但它給了我一個“無法在初始化”消息中將'boost :: python :: api :: const_object_item'轉換為'int'。

shape[0]為您提供了一個Python對象。 要將其轉換為int或其他C ++類型,您需要提取值:

int x = extract<int>(shape[0]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM