473,394 Members | 1,641 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,394 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 1150
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 the scene he tells of his sordid sex life and...
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 have a function like this : def show_lines(file):...
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 containers). The container stores some session...
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 source through a function and returns an instance of a...
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 called when a new instance is created, as below. ...
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 follows: CREATE DATABASE database1 ON...
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 is troubling to me is in the diag log i see that it...
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 class, through this single global instance. Are...
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). How to write the acccesor method (instance()) to...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.