Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 0.53 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Writing a Python C extension: how to correctly load a PyListObject?
  2. static PyObject *orbital_spectra(PyObject *self, PyObject *args) {
  3.   PyListObject *input = (PyListObject*)PyList_New(0);
  4.   real channels[7], coefficients[7], values[240];
  5.   int i;
  6.  
  7.   if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &input)) {
  8.     return NULL;
  9.   }
  10.   for (i = 0; i < PyList_Size(input); i++) {
  11.     printf("%fn", PyList_GetItem(input, (Py_ssize_t)i)); // <--- Prints zeros
  12.   }
  13. //....
  14. }
  15.        
  16. printf("%fn", PyFloat_AsDouble(PyList_GetItem(input, (Py_ssize_t)i)));