python - 为什么 PyArg_ParseTuple 总是返回 false?

标签 python c++ python-extensions

我的 PyFLoat_ParseTuple 调用总是返回 false,从 python 端调用正确。

我正在为 Python 包装我的 C++ 并使用 Python 扩展。 我有一个成功的项目,并以此为基础生成了当前的项目。
我的 python 运行总是崩溃,在调查期间我将我的代码减少到以下最小代码以重复它。

如果我将 C++/Python 端都更改为非参数调用,它会按预期工作。 但是当我传入 args 时总是打印“解析错误”。

C++:

static PyObject *myfunc(PyObject *self, PyObject *args)
{
    float v[6];
    if (!PyArg_ParseTuple(args, "ffffff", v,v+1,v+2,v+3,v+4,v+5));
    { 
                //I can alway see this prited.
        cerr<<"Parse error\n";
        return NULL;
    }
        return PyString_FromFormat("No error!\n");
}

python :

print func(0.1,0.2,0.3,0.4,0.5,0.6)

最佳答案

一个非常简单的错字:

if (!PyArg_ParseTuple(args, "ffffff", v,v+1,v+2,v+3,v+4,v+5));

- 看到 if 末尾的分号 ;?

关于python - 为什么 PyArg_ParseTuple 总是返回 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55954300/

相关文章:

c++ - 顺序一致性和获取/释放语义之间有什么区别?

C++ 递归排序算法不需要数组长度

python - 使用 distutils 为 python 扩展构建 RPM 时的相对包含路径

python - 在 C 扩展段错误中创建 numpy 数组

c++ - 线程本地存储和 iOS

c++ - 在 IronPython 的解释器 (ipy.exe) 中导入 *.pyd 库

python - 使用 WSGI 和 Python 3 提供静态文件

python - pygame.错误: video system not initialized(pycharm)

python - 如何在Python中将多级别的API响应转换为数据帧

python - 如何连续多次从列表中生成随机项目,但每次都会生成不同的项目