search

Home  >  Q&A  >  body text

python - How to convert char* object to PyObject* object

is used for function parameter transfer, so PyObject_GetAttrString cannot be used

漂亮男人漂亮男人2749 days ago1098

reply all(1)I'll reply

  • 滿天的星座

    滿天的星座2017-06-10 09:50:40

    PyByteArray_FromStringAndSize or Py_BuildValue first converts char * into bytes
    Then PyTuple_SetItem converts bytes into tuple

            PyObject * bytesObject = PyByteArray_FromStringAndSize(message, len);
            PyObject * buildObject = Py_BuildValue("y#", message,len);
            PyObject * argsObject = PyTuple_New(1);
            PyTuple_SetItem(argsObject, 0, bytesObject);
    

    reply
    0
  • Cancelreply