1 回答

TA贡献1946条经验 获得超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是一个方法然后调用它,不要只是获取它:
PyObject * res = PyObject_CallMethod(pValue, "gettext", NULL);
添加回答
举报