473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

prob. creating deeply nested structures in Py/c api

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
Jul 18 '05 #1
1 1757
On 2004-02-28 08:41:47 -0500, Ori Y <ge*****@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

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: OKB (not okblacke) | last post by:
For a variety of reasons, I'm interested in putting together some code that will allow me to created structures out of nested classes, something like: class class1: def methA(self): print...
6
by: josephrthomas | last post by:
hi..i am trying to make a login page and i am using access table.. when the user enters his userid and password i want to check the password from the table.. if any user with the userID that is...
20
by: svend | last post by:
I'm messing with some code here... Lets say I have this array: a1 = ; And I apply slice(0) on it, to create a copy: a2 = a1.slice(0); But this isn't a true copy. If I go a1 = 42, and then...
28
by: Vishal Naidu | last post by:
i m new to the C world... i ve been told by my instructors not to use goto stmt.. but no one could give me a satisfactory answer as to why it is so.. plz help me out of this dilemma, coz i use...
11
by: Alfonso Morra | last post by:
Hi, I have the ff data types : typedef enum { VAL_LONG , VAL_DOUBLE , VAL_STRING , VAL_DATASET }ValueTypeEnum ;
8
by: Simon Edwards | last post by:
Something thats been bugging me for a while... how do you create a namespace that has many children (namespaces) I.e system.io.blah.blah Iv'e done it by creating a class which contains...
4
by: ECathell | last post by:
I had read an article at one time that suggested a pattern to get around deeply nested if..then..else hell... Can anyone point me in that direction? select case statements wont work for me in...
7
by: Kay Schluehr | last post by:
I want to manipulate a deeply nested list in a generic way at a determined place. Given a sequence of constant objects a1, a2, ..., aN and a variable x. Now construct a list from them recursively:...
3
by: Bartholomew Simpson | last post by:
I am writing some C++ wrappers around some legacy C ones - more specifically, I am providing ctors, dtors and assignment operators for the C structs. I have a ton of existing C code that uses...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.