473,778 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_FromSt ring("foo"),PyI nt_FromLong(x)) ; //setting first dict

//setting dict1 in dict2 and returning dict2

PyDict_SetItem( dict2, PyString_FromSt ring("blah"),di ct1);
// expected {blah:{foo:1}}


---------------------------------
Do you Yahoo!?
Get better spam protection with Yahoo! Mail
Jul 18 '05 #1
1 1792
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_FromSt ring("foo"),PyI nt_FromLong(x)) ;
//setting first dict
//setting dict1 in dict2 and returning dict2

PyDict_SetItem( dict2, PyString_FromSt ring("blah"),di ct1); // 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
2161
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 "Some code here" class class2: propA = "A" def methB(self):
6
2755
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 entered exists i want to find the correspoding password for him else i want to throw an error saying no such user exists.. i know how to access the MS Access table and stuff..but
20
3125
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 alert(a2) I will see 42 there too. I'm doubting, but I was
28
2731
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 a lot of goto in my codes....
11
2014
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
9092
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 another class. i can see the properties of the first class and the namespace of the second (inner class) but can't see the properties of the 2nd....
4
2524
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 this instance -- --Eric Cathell, MCSA
7
1320
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: L = ]...]] The value of x is the only one to be changed. With each value of x a new instance of L is needed so that we actually have a function: L = lambda x: ]...]]
3
2284
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 these structs. A typical usage case will be as ff (note the code below is Pseudocode and WILL NOT compile) //example structs (I have left out the ctors/dtors etc for brevity sake) struct MyStructA
0
9465
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10068
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7474
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2863
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.