obj in list and list ids the same

Laurence Tratt tratt at dcs.kcl.ac.uk
Tue Dec 28 07:17:13 EST 1999


In message <84a8k4$puq$1 at nnrp1.deja.com>
          rdudfield at my-deja.com wrote:

> I've got a problem where a list has the same id as a object instance in
> that same list.  This is as returned by id().

If you're using CPython, then this is *very* unlikely (I can't speak for the
other implementations); id() returns the memory address of a given object
and unless malloc or something has gone wrong then id() will always return
unique numbers for different objects[0].

So if you've genuinely got a list with something inside the list with the
same id, you've probably append'ed your list into itself.


Laurie

[0] With the - obvious, given the implementation - caveat that objects with
      different lifetimes may have the same id
-- 
http://eh.org/~laurie/comp/python/



More information about the Python-list mailing list