Operabilite entre python et C

stabiloc Messages postés 2 Date d'inscription mardi 3 mars 2009 Statut Membre Dernière intervention 3 mars 2009 - 3 mars 2009 à 10:41
stabiloc Messages postés 2 Date d'inscription mardi 3 mars 2009 Statut Membre Dernière intervention 3 mars 2009 - 3 mars 2009 à 17:07
Bonjour,

J'aimerais creer un hash en python. Depuis C je désire
appeler les éléments du Hash(bibliothèque).
.py

Citation:
dictionnaire
= {"rrg" : 25, 854 : "TZSZHSRTZ", "gdf" : 47};

class Dico():

def
PythonGet(self) :
return dictionnaire
print "dictionnaire", dictionnaire

.c

Citation:
#include
<stdio.h>
#include <C:\Python25\include\Python.h>

PyObject
*mymod, *func, *retval;

int CallPythonGet(void){
char* js;
func = PyObject_GetAttrString(mymod,
"PythonGet");
retval = PyEval_CallObject(func,NULL);
PyArg_Parse(retval,
"c",&js); //fonction a
remplacer.
return js;
}

int main(void){
char*
_result;
Py_Initialize();
mymod =
PyImport_ImportModule("dictionnarie");

_result =
CallPythonGet();
printf ("Python
Get_Global_Var:%u\n",_result);

Py_Finalize();
printf("Press touch
to continue");
getchar();
return 0;
}

Je pense qu'il faut utiliser la fonction suivant au lieu de 

Citation:
int
PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format,
char *keywords[], ...)¶
Parse the parameters of a function that takes both
positional and keyword parameters into local variables. Returns true on success;
on failure, it returns false and raises the appropriate exception.

a la place de PyArg_Parse(retval,
"c",&js);

Avez vous deja rencontré ce problème?
Merci

1 réponse

stabiloc Messages postés 2 Date d'inscription mardi 3 mars 2009 Statut Membre Dernière intervention 3 mars 2009
3 mars 2009 à 17:07
resolu
0
Rejoignez-nous