By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,091 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,091 IT Pros & Developers. It's quick & easy.

to ask an container instance to suicide

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.