Python C 扩展关键字参数

标签 python c python-c-extension

问题描述:

当我调用这样定义的方法时:

static PyMethodDef Parser_methods[] = {
    {"read", (PyCFunction)Parser_read, METH_KEYWORDS, "read from input source"},
    {NULL, NULL, 0, NULL} 
};

static PyObject *
Parser_read(Parser * const self, PyObject * unused0, PyObject * unused1)
{
...
}

我得到:

SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported!

代码在 Python2 上运行正常,但在 Python3 上崩溃

最佳答案

可能是这个错误...

http://bugs.python.org/issue11587

这意味着这是一个python版本问题。一种修复似乎是使用 METH_KEYWORDS | METH_VARARGS .

关于Python C 扩展关键字参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28857522/

相关文章:

c - 如何将与 OpenGL 一起使用的纹理嵌入到 C 数组中?

Python C 扩展 - 错误 `python3.6' : free(): invalid pointer: 0x

python - 使用 C API 创建自定义类对象的 numpy 数组

python - 尝试将带有数字的 txt 文件读入列表,然后使用 Python 进行排序

python - Hadoop MapReduce Streaming 输出与本地运行 MapReduce 的输出不同

c - 字符串字符出现次数

c - 如何在Linux中使用SOCK_RAW接收IPv4数据包?

python - 如何安装 libsandbox?我在安装过程中遇到一些问题

python - Pycharm 在创建新项目时不显示框架选择

python - 在固定时间内接受多个输入