/* C_test.c file to test imorting C modules to Python */ #include "C_test.h" #include /* Globals */ /* Set up the methods table */ static PyMethodDef C_testMethods[] = { {"square", square, METH_VARARGS}, {"squarert", squareroot, METH_VARARGS}, {NULL, NULL} /* Sentinel */ }; /* Test a simple C function, square */ /* Initialize the C_test functions */ void initC_test() { (void) Py_InitModule("C_test", C_testMethods); } /* square function */ static PyObject *square(PyObject *self, PyObject *args) { double x,y; if (!PyArg_ParseTuple(args, "d", &x)) return NULL; y=x*x; return Py_BuildValue("d", y); } /* squareroot function */ static PyObject *squareroot(PyObject *self, PyObject *args) { double x,y; if (!PyArg_ParseTuple(args, "d", &x)) return NULL; y=mysqrt(x); return Py_BuildValue("d", y); } /* my square root function, internal to C */ double mysqrt(double z) { return sqrt(z); } /* end C_test.c */