【发布时间】:2021-02-06 16:58:07
【问题描述】:
我想知道Pyrun_String的返回怎么用。
我已经尝试过使用PyUnicode_DATA 和PyObject_Str。
if (!(pstr = PyRun_String("a = 1", Py_single_input, pGlobal, pdict)))
exit(printf("Error while running string\n"));
// I tried this
PyObject *pstr = PyObject_Str(pstr);
void* test = PyUnicode_DATA(pstr);
printf("%s\n", (char*)test);
// or this
if (!PyArg_Parse(pstr, "s", &cstr))
exit(printf("Bad result type\n"));
printf("%s\n", cstr);
【问题讨论】:
标签: python c python-c-api