15.15 C字符串转换为Python字符串
问题
解决方案
char *s; /* Pointer to C string data */
int len; /* Length of data */
/* Make a bytes object */
PyObject *obj = Py_BuildValue("y#", s, len);PyObject *obj = Py_BuildValue("s#", s, len);PyObject *obj = PyUnicode_Decode(s, len, "encoding", "errors");
/* Examples */
obj = PyUnicode_Decode(s, len, "latin-1", "strict");
obj = PyUnicode_Decode(s, len, "ascii", "ignore");讨论
Last updated