prob. creating deeply nested structures in Py/c api

Discussion in 'Python' started by Ori Y, Feb 28, 2004.

  1. Ori Y

    Ori Y Guest

    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}}






    ---------------------------------
    Do you Yahoo!?
    Get better spam protection with Yahoo! Mail
     
    Ori Y, Feb 28, 2004
    #1
    1. Advertising

  2. Ori Y

    Bob Ippolito Guest

    On 2004-02-28 08:41:47 -0500, Ori Y <> 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
     
    Bob Ippolito, Feb 28, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edward C. Jones

    Pickle vs. eval for deeply nested objects

    Edward C. Jones, Feb 18, 2004, in forum: Python
    Replies:
    0
    Views:
    511
    Edward C. Jones
    Feb 18, 2004
  2. Kirk Strauser
    Replies:
    1
    Views:
    318
    Kirk Strauser
    Jun 11, 2004
  3. Kay Schluehr
    Replies:
    7
    Views:
    381
    Kay Schluehr
    Jan 20, 2006
  4. Alfonso Morra
    Replies:
    11
    Views:
    753
    Emmanuel Delahaye
    Sep 24, 2005
  5. eminemence
    Replies:
    4
    Views:
    1,201
    Tim Slattery
    Dec 10, 2007
Loading...

Share This Page