OOP - iterable class: how to delete one of its objects ?
R.Wieser
address at not.available
Fri Nov 1 15:15:55 EDT 2019
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
More information about the Python-list
mailing list