
27 Jan
2009
27 Jan
'09
6:20 a.m.
(sorry, accidentally hit 'send')
Gamze Tunali wrote:
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.
You may want to leave these things to Cython:
cdef class dbvalue:
cdef unsigned int id
cdef str type
def __init__(self, index, type):
self.id = index # will raise an exception if not uint
self.type = type.encode('ASCII')
...
class ...:
def set_input_from_db(self, someval, dbvalue value):
print someval, value.id, value.type
Cython will translate this to efficient C code for you.
Stefan