472,334 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

to ask an container instance to suicide

Hi,
I have containers to hold geometrical objects. The members in these
containers can again be containers them self. Now, In the program I
would be moving objects from one container to another. In this process,
If the number of members in one of the containers becomes just one, I
want to delete that container and have only its only member in place of
it in the parent container.
I have implemented setting and getting the container members using
property().

Right now, I am planning to do this this way:
Maintain a reference to parent container in each container.
When the condition is detected, do self.parent.deleteObject(self) .

def deleteObject(self,memberId):
index = self._members.index(memberId)
self._members[index] = memberId._members[0]
del memberId

Will this work. Or is there any other simple way to do this?
--
Suresh

Nov 20 '06 #1
2 1098
jm*******@no.spam.gmail.com wrote:
Hi,
I have containers to hold geometrical objects. The members in these
containers can again be containers them self. Now, In the program I
would be moving objects from one container to another. In this process,
If the number of members in one of the containers becomes just one, I
want to delete that container and have only its only member in place of
it in the parent container.
I have implemented setting and getting the container members using
property().

Right now, I am planning to do this this way:
Maintain a reference to parent container in each container.
When the condition is detected, do self.parent.deleteObject(self) .

def deleteObject(self,memberId):
index = self._members.index(memberId)
self._members[index] = memberId._members[0]
del memberId

Will this work. Or is there any other simple way to do this?
--
Suresh
I don't understand what you want to achieve, but there are 2 things I
can say: "del memberId" is useless, it is deleted anyway when memberId
goes out of scope. Because you have a 2-way reference, have one of them
(the parent reference would be better) a weakref. Else, you'll be
leaking memory.

Nov 20 '06 #2
jm*******@no.spam.gmail.com wrote:
Hi,
I have containers to hold geometrical objects. The members in these
containers can again be containers them self. Now, In the program I
would be moving objects from one container to another. In this process,
If the number of members in one of the containers becomes just one, I
want to delete that container and have only its only member in place of
it in the parent container.
I have implemented setting and getting the container members using
property().

Right now, I am planning to do this this way:
Maintain a reference to parent container in each container.
When the condition is detected, do self.parent.deleteObject(self) .

def deleteObject(self,memberId):
index = self._members.index(memberId)
self._members[index] = memberId._members[0]
del memberId

Will this work. Or is there any other simple way to do this?
I wouldn't implement it this way. I'd rather have a reducer in place - it is
benefitial to have a way of visiting you tree of objects. Then you could
employ a reducing-scheme that will replace childnodes of a node with their
single child as optimization.

Diez
Nov 20 '06 #3

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

Similar topics

0
by: jason.davis | last post by:
Early this morning Arnold Schwarzenegger was found hanging by his neck from the large oak tree in his Californian garden. In a suicide note found at...
9
by: sc_wizard29 | last post by:
Hi everyone, Maybe these questions will sound strange to you, but I sometime have a hard time switching from Java to Python ;-) Let's say I...
1
by: toton | last post by:
Hi, I need to store some suicidal class to a container like deque. ( I am not using boost container library for pointers at this moment, using stl...
3
by: Cristiano Paris | last post by:
Hi everyone, I'm trying to write a Container which should mimic a list. Basically, the container pulls items on the fly from an unspecified...
2
by: Daniel Lipovetsky | last post by:
I would like for an object to "report" to a container object when a new instance is created or deleted. I could have a container object that is...
3
by: Pat | last post by:
Hi - We're trying to set up an HADR pair on two databases on instances with different names on separate servers. The databases were defined as...
0
by: Lew | last post by:
Hi, I have a database that I am restoring to another database in the same instance using a redirected restore. It seems to work fine but what...
36
by: Peter Olcott | last post by:
So far the only way that I found to do this was by making a single global instance of the container class and providing access to the contained...
4
by: Bit Byter | last post by:
I want to write a (singleton) container for instances of my class templates, however, I am not too sure on how to: 1). Store the instances 2)....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.