[Python-Dev] How pass array from C to python function

Praveen Patil praveen.patil@silver-software.com
Thu, 19 Sep 2002 14:39:43 +0100


Hi ,

I have problem in passing array to python function.
Please help me passing array to python function.

Here is my  'C' program
-----------------------

void  RECEIVE_IL_STATE_S( int Instance , int vital_data[5])
{
    PyObject*arglist;
    PyObject* ret;
    PyObject* mylist;
    int count;
    
    mylist = PyList_New(5);
    for (count=0; count< 5; count++) {
          myint = PyInt_FromLong(vital_data[count]);
          PyList_Append(mylist,myint); 
    }
    arglist = Py_BuildValue("O", mylist);
    ret = PyEval_CallObject(my_callback , arglist);
    Py_DECREF(arglist);
    Py_DECREF(ret);
} 

Here is my Python program
-------------------------

G_Logfile          = None

def TestFunction(a):
    G_Logfile = open('Pytestfile.txt', 'w')
    G_Logfile.write("%d \n"% a[0])
    G_Logfile.write("%d \n"% a[1])
    G_Logfile.close


Cheers,

Praveen.

















[ The information contained in this e-mail is confidential and is intended for the named recipient only. If you are not the named recipient, please notify us by telephone on +44 (0)1249 442 430 immediately, destroy the message and delete it from your computer. Silver Software has taken every reasonable precaution to ensure that any attachment to this e-mail has been checked for viruses. However, we cannot accept liability for any damage sustained as a result of any such software viruses and advise you to carry out your own virus check before opening any attachment. Furthermore, we do not accept responsibility for any change made to this message after it was sent by the sender.]