Removing objects

bladedpenguin at gmail.com bladedpenguin at gmail.com
Wed Jan 23 01:59:07 EST 2008


I am writing a game, and it must keep a list of objects. I've been
representing this as a list, but I need an object to be able to remove
itself. It doesn't know it's own index. If I tried to make each object
keep track of it's own index, it would be invalidated when any object
with a lower index was deleted.  The error was that when I called
list.remove(self), it just removed the first thing in hte list with
the same type as what I wanted, rather than the object I wanted. The
objects have no identifying charachteristics, other than thier
location in memory

So my question: How do I look something up in a list by it's location
in memory? does python even support pointers?

Is there a better way?



More information about the Python-list mailing list