to ask an container instance to suicide

Diez B. Roggisch deets at nospam.web.de
Mon Nov 20 09:30:33 EST 2006


jm.suresh at 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



More information about the Python-list mailing list