REMOVE ME

Chris Angelico rosuav at gmail.com
Sat Apr 9 23:52:07 EDT 2016


On Sun, Apr 10, 2016 at 1:46 PM, fan nie <niefan68 at gmail.com> wrote:
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Sure. I presume you mean something like this:

class Thing:
    things = []
    def __init__(self):
        self.things.append(self)
    def __del__(self):
        # Remove me when I'm dead
        self.things.remove(self)

This ingenious technique guarantees that you never have dead objects
in your list, by having each object remove itself when it dies.

ChrisA



More information about the Python-list mailing list