obj in list and list ids the same

rdudfield at my-deja.com rdudfield at my-deja.com
Tue Dec 28 12:22:05 EST 1999


In article <daee7b7749.laurie at btinternet.com>,
  Laurence Tratt <tratt at dcs.kcl.ac.uk> wrote:
> 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

 Forgot to mention, I'm using python 1.5.2 on linux 2.2.12, on a cyrix 266,
and a celron system, same problems on both.  I don't know about the lifetime
problem, but I'm not appending the list into itself, the object in there is a
instance of a shape object.  Could the problem be with copy.copy maybe?  The
library reference docs don't sound to reassuring.  I might try moving the
method out of the object into a function.  But that will take a while, and
should use up heaps more memory :(

Thanks for your reply.


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list