我正在整合我的 C 和 Python 代码。我需要从 python 发送一个字符串,“a_string”,
>>>dicho("a_string")
在我下面的 C 程序中,我需要接收带有变量 unsigned char * 的“a_string”。
static PyObject* dicho(PyObject* self, PyObject* args){
unsigned char * cleartext;
PyArg_Parse(args, TYPE, &cleartext);
我将如何做到这一点? PyArg_ParseTuple、s、s# ... 中需要什么类型?
最佳答案
使用 PyArg_ParseTuple
和 s#
格式。这为您提供了一个 const char *
指针,您可以将其转换为 const unsigned char *
。
关于python - 解析参数和构建值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25293954/