How to delete yourself????

christian.siegl at gmail.com christian.siegl at gmail.com
Fri Oct 14 16:25:04 CEST 2005


Hello,


I got a problem deleting objects, which are placed in a hirarchy....

Asume we have the following code:
########################################################
class parent:

    MyChilds = [] # this list is filled with childs....

    def AddChild(self, child):
        # add childs here, however this is done, it's not the point...
        child.MyParent = self

    def RemoveChild(self, child):
        # delete child from the list.... the way this is done is not
our
        # problem here


class child:

    MyParent = 0

    def deleteMe(self):
        MyParent.RemoveChild(self)
##############################################################

So my code looks something like that.... and it works. I works because
you do not touch any member variables in class child after deleting
it... But is this nice code??? Is there another way to delete
yourself???

Thanks for any comments...
Chris




More information about the Python-list mailing list