1 回答

TA貢獻1946條經(jīng)驗 獲得超3個贊
返回PyObject_GetAttrStringa PyObject *,正確處理它,這是代碼:
pFunc_readtest = PyObject_GetAttrString(pModule, "ReadDataTest");
if (pFunc_readtest && PyCallable_Check(pFunc_readtest)) {
pValue = PyObject_CallObject(pFunc_readtest, NULL);
if(pValue != NULL) {
PyObject * res = PyObject_GetAttrString(pValue, "gettext");
if (!PyUnicode_Check(res)) {
// not a string, return error here
}
std::string m_gettextFunction = std::string(PyUnicode_AsUTF8(res));
printf("Result of call: %c\n", m_gettextFunction);
Py_DECREF(pValue);
}
}
如果gettext是一個方法然后調(diào)用它,不要只是獲取它:
PyObject * res = PyObject_CallMethod(pValue, "gettext", NULL);
添加回答
舉報