2011-04-30 47 views
0

可以说我有从主文件形式的.py不读成C

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); 
} 
浮动X

确定问题出在我的C程序从蟒蛇接收0而不是3号我浮法X

回答

0

试试这个:

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); 
} 
0

在我看来,问题可以通过使用int而不是float来解决。 Python变量默认保存12字节的内存,“C float”只保存4.第二种选择是使用PyTypeObject PyFloat_Type,它指定float类型是必需的。