cython structure, string from python to cython

Viewed 659

i would like to convert a python object to cython structure by doing as i did bellow, but it doesn't assigns the values of simres[1] to the resulta[x].cpt1

cdef struct resultaStructure:
    double score
    char **cpt1

simRes = [1.0,
['http://bioontology.org/projects/ontologies/fma/fmaOwlDlComponent_2_0#Abdomen', 
'Abdomen']]
cdef x = 0 
cdef resultaStructure *resulta = <resultaStructure *> malloc(sizeof(resultaStructure)*labelsSourceTaille)

resulta[x].score = simRes[0]
print("score : ",resulta[0].score)

resulta[x].cpt1 = <char**> malloc (sizeof (char**)*2)
print('2')
resulta[x].cpt1[0] = <char*> malloc (sizeof (char)*simRes[1][0].__len__()+1)
print('3')
resulta[x].cpt1[1] = <char*> malloc (sizeof (char)*simRes[1][1].__len__()+1)
print('4')
resulta[x].cpt1[0] = <char*> simRes[1][0]
print('5')
resulta[x].cpt1[1] = <char*>  simRes[1][1]
print('6')

print("cpt1 0 : ",resulta[0].cpt1[0])
print("cpt1 1 : ",resulta[0].cpt1[1])

here is the result

('score :', 1.0)

2

3

4

2 Answers
Related