Converting a Python List to a C double *

Joakim Hove hove at phys.ntnu.no
Fri Apr 26 06:16:52 EDT 2002


Hello,

I am writing a C-extension, and now I need to parse a list from python
into a c double *:

   static PyObject * power(PyObject *self, PyObject *args) {
     double *xdata;
   
     /*
       This routine shall be called from Python. It will always be
       called with a variable length list of floats: e.g. 
       module.power([0.1, 0.2, 0.45, 0.60, 0.70]).
     
       Within the c-function "power" I want to access the list in the
       pointer xdata. How to parse?
     */
     
     


     for (i=0; i<5; i++) 
       printf("x[%d] = %12.7f \n",i,xdata[i]);
     return PyNone();
   }  

Grateful for any suggestions - 

Joakim Hove


-- 
==== Joakim Hove      www.phys.ntnu.no/~hove/   =======================
|| Institutt for fysikk  (735) 93637 / E3-166  |  Skøyensgate 10D    ||
|| N - 7491 Trondheim    hove at phys.ntnu.no     |  N - 7030 Trondheim ||
================================================= 73 93 31 68 =========



More information about the Python-list mailing list