I'm writing a c extension to calculate he standard deviation. Performance is important because it will be performed over large data sets. I'm having a hard time figuring out how to get the value of pyobject once I get the item from a list. This is my first time writing a c extension for python and any help is appreciated. Apparently I don't know how to use the code sample button correctly :(
This is what I have so far:
#include <Python.h>
static PyObject*
func(PyObject *self, PyObject *args)
{
PyObject *list, *item;
Py_ssize_t i, len;
if (!PyArg_UnpackTuple(args, "func", 1, 1, &list)){
return NULL;
}
printf("hello world\n");
Py_INCREF(list);
len = PyList_GET_SIZE(list);
for (i=0;i<len;i++){
item = PyList_GET_ITEM(list, i);
PyObject_Print(item,stdout,0);
}
return list;
}
static char func_doc[] = "This function calculates standard deviation.";
static PyMethodDef std_methods[] = {
{"func", func, METH_VARARGS, func_doc},
{NULL, NULL}
};
PyMODINIT_FUNC
initstd(void)
{
Py_InitModule3("std", std_methods, "This is a sample docstring.");
}