python - 解析参数和构建值

标签 python c

我正在整合我的 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_ParseTuples# 格式。这为您提供了一个 const char * 指针,您可以将其转换为 const unsigned char *

关于python - 解析参数和构建值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25293954/

相关文章:

c - 在c中将一个指针分配为等于另一个指针的值

c - 如何配置此错误以能够正确生成Makefile?

c# - SysInternal 的 ProcessMonitor 是如何工作的?

C implicit extern for global variable,什么时候发生,它是如何工作的

python - Ruby optparse 限制

python - Python用在什么地方?我在 Reddit 上读了很多

c++ - 如何在 "edit"按键上杀死 "Enter"控件的焦点

python - 2D numpy 数组的 2D python 列表到 2D numpy 数组

列表中单个元素的 Python struct.pack()?

python - 如何在 gtk3-python 中执行后台任务?