问题描述:
当我调用这样定义的方法时:
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/