prob. creating deeply nested structures in Py/c api
Bob Ippolito
bob at redivi.com
Sat Feb 28 15:05:22 EST 2004
On 2004-02-28 08:41:47 -0500, Ori Y <geensys at yahoo.com> said:
>
> Hi , i'm having some difficulties regarding using the Python/c api.
> I'm trying to bulid a deeply nested datastructure (i.e dict within a
> dict or list within a dict)
> Building the data stracture seems ok on interperter, but after few
> calls to the method
> returning the structure, and aft applying the Ctrl+D to exit interperter
> i receive a 'segmentation fault'. ?#
> Further more when calling the program from python i receive the
> dictionary as a string!
> "{foo: {1:'blah, 2:'boo'}, bar:1}" (i have a feeling these problems
> are related).
> I'm using python 2.3 on a RH9 Linux machine.
> Advise would be very much appriciated.
> Here is a shorter example of the consept i'm trying to do :
> static *PyObject blah (something)
> {
> PyObject *dict1;
> PyObject *dict2;
> long x;
> dict1 = PyDict_New();
> dict2 = PyDict_New();
> x = 1;
> PyDict_SetItem(dict1, PyString_FromString("foo"),PyInt_FromLong(x));
> //setting first dict
> //setting dict1 in dict2 and returning dict2
>
> PyDict_SetItem(dict2, PyString_FromString("blah"),dict1); // expected
> {blah:{foo:1}}
You should try Pyrex:
http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/
It would make this just as easy as it is in Python.
-bob
More information about the Python-list
mailing list