假设我有来自 main 的 float x
import progC
def main():
x = 3
y=progC(x)
print y
if __name__ == __main__
main()
<小时/>
#include <Python.h>
static PyObject* py_bracket(PyObject* self, float x){
x = x+5;
return Py_BuildValue("d",x);
}
好的问题是我的 C 程序中的 float x 从 python 接收到 0 而不是数字 3
最佳答案
试试这个:
static PyObject* py_bracket(PyObject* self, PyObject* args){
float x;
if (!PyArg_ParseTuple(args, "f", &x))
return NULL;
x = x+5;
return Py_BuildValue("f",x);
}
关于python - .py 形式的文件未读入 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5842342/