文章详情页
python - 怎么把char*对象转换成PyObject*对象
问题描述
用在函数传参上,所以没法用PyObject_GetAttrString
问题解答
回答1:PyByteArray_FromStringAndSize 或者Py_BuildValue先把char *转成bytes然后PyTuple_SetItem把bytes 转成tuple
PyObject * bytesObject = PyByteArray_FromStringAndSize(message, len);PyObject * buildObject = Py_BuildValue('y#', message,len);PyObject * argsObject = PyTuple_New(1);PyTuple_SetItem(argsObject, 0, bytesObject);
相关文章:
排行榜