我最近开始使用Python / C API使用C代码为Python构建模块。我一直在尝试将Python的数字列表传递给C函数,但没有成功:
asdf_module.c
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <Python.h>
int _asdf(int low, int high, double *pr)
// ...
for (i = 0; i < range; i++)
{
printf("pr[%d] = %f\n", i, pr[i]);
}
// ...
return 0;
}
static PyObject*
asdf(PyObject* self, PyObject* args)
{
int low, high;
double *pr;
// maybe something about PyObject *pr ?
if (!PyArg_ParseTuple(args, "iiO", &low, &high, &pr))
return NULL;
// how to pass list pr to _asdf?
return Py_BuildValue("i", _asdf(low, …Run Code Online (Sandbox Code Playgroud)