【问题标题】:Python C Extension Keyword argumentsPython C 扩展关键字参数
【发布时间】:2015-03-04 14:52:23
【问题描述】:

问题描述:

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

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 上崩溃

【问题讨论】:

    标签: python c python-c-extension


    【解决方案1】:

    可能是这个错误...

    http://bugs.python.org/issue11587

    这意味着这是一个 python 版本问题。一种解决方法似乎是使用METH_KEYWORDS | METH_VARARGS

    【讨论】:

    • 刚刚遇到了同样的问题。我不确定如何或在哪里设置 METH_KEYWORDS | METH_VARARGS,非常感谢您的澄清。
    【解决方案2】:

    Parser_read 应该是

    static PyObject* Parser_read(PyObject *self, PyObject *args)
    

    【讨论】:

    • 不对,他用的是关键字形式。
    猜你喜欢
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 2013-03-06
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多