Parsing a Python dictionary inside a Python extension
tiissa
tiissa at nonfree.fr
Sat May 28 15:41:27 EDT 2005
quadric at primenet.com wrote:
> I tried something like this and it has not worked.
Oh! What did you ask of it, what did you expect and what did you get?
> if ( (item = PyDict_GetItemString( vdict , "atab1")) != NULL )
> PyArg_ParseTuple( item , "i" , &atab1 );
This code expects a dictionary in which keys 'atab1' and 'atab2' are
singletons of integer. If that's what you want, I'd say it should work.
> // ndict = Py_BuildValue( ........create dictionary here ..........)
>
> return ndict ;
> }
I personnally prefer 'return Py_BuildValue("");' than returning NULL
pointers (but I don't like to check the doc just to make sure NULL can
be interpreted as None).
In order to build a dictionary you could try:
...
return Py_BuildValue("{s:i,s:i}", "key1", atab1, "key2", atab2);
}
Or even "{s:(i),s:(i)}" to have singletons for values.
HTH
More information about the Python-list
mailing list