git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

OOP - iterable class: how to delete one of its objects ?


Hello all,

I've created a class from which I can iterate all its instanciated objects 
(using an "instances" list).    The problem is that I now cannot seem to 
delete an object anymore, AFAIK as a copy of its "self" is still inside the 
"instances" list.

Object in question:
- - - - - - - - - - - - - - - -
class TheObject:
    instances = []

    def __init__(self):
        self.instances.append(self)

    def __del__(self):
        print("Deleted!")
- - - - - - - - - - - - - - - -

The question: How can I keep the class iterable, but still have it delete 
itself when asked.

Regards,
Rudy Wieser