[capi-sig] Passing an object from script to C code

Gamze Tunali gdtunali at yahoo.com
Tue Jan 27 03:56:31 CET 2009


Hi,

As a beginner, I have a question about passing a class instance from Python script to my C code. 
What I am doing is basically creating a class in the script:

class dbvalue:
  def __init__(self, index, type):
    self.id = index    # unsigned integer
    self.type = type   # string

last_roi = dbvalue(id, type);
bmdl_batch.set_input_from_db(1, last_roi); <--------

I would like to call my C function with last_roi and able to recover id and type in the code. The C part is follows:


PyObject *set_input_from_db(PyObject* self, PyObject *args)
{
  unsigned input;
  PyObject *obj;

  if (!PyArg_ParseArg(args, "iO:set_input_from_db", &input, &obj))
    return NULL;

  ....
}

I am not sure if PyArg_ParseArg() is the right method to get the object. I used "O:.."  to get it but after that, how do I acces index and type fields of the object. Do I create an equivalent class/struct in C code to? Again, all I want is pass the 2 values together in an object and able to recover then in C code.

Thanks,

Gamze 



      


More information about the capi-sig mailing list