從c/c
中提取返回值的返回值,從c/c調用自定義python函數允許允許擴展功能,但提取返回值可能是具有挑戰性的。這是使用Python c-api。 Python Module c/c code
導入c/c(test.cpp)中的python3 Inverteter:導入並調用function
獲取函數的參考: pyobject* args = pytuple_pack(1,pyfloat_fromdouble(2.0));
Extracting the Return Value
import math def myabs(x): return math.fabs(x)Convert the result to a double:
double result = PyFloat_AsDouble(myResult);
Usage
import math def myabs(x): return math.fabs(x)In your C/C code, you can now use the提取的返回值(結果):
記住在這些操作過程中記住任何錯誤。有關C-API的更多詳細信息,請參閱官方文檔。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3