obj in list and list ids the same
Neel Krishnaswami
neelk at brick.cswv.com
Wed Dec 29 17:58:48 EST 1999
rdudfield at my-deja.com <rdudfield at my-deja.com> wrote:
>Hello,
>
>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().
>
>Is this ever supposed to happen? I just thought this was odd. This happens
>when I am trying to copy a list of objects (sheets ) in the current object
>into a object which is also in a list( not the same one). Then I try to copy
>a object (shape) from a global list into a list inside a sheet object which
>is inside a list in the node object.
If the id()'s are the same, then you have managed to create a circular
reference in your list. Eg:
Python 1.5.2 (#8, May 12 1999, 17:46:31) [GCC 2.7.2.1] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> x = []
>>> x.append(x) # create a circular reference
>>> id(x)
135060792
>>> id(x[0])
135060792
Double-check your code to make sure that the list assignments can
never reference themselves (unless that's what it's supposed to do, of
course). Lots of can't-happen cases turn out to actually be possible
when the code is run. :(
Note that circular references can't be automatically garbage-collected
under CPython -- only Viper and JPython can currently gc circular
references. This isn't normally a problem unless you create a *lot* of
circular garbage, or if the script will run for a long time (like as a
daemon process).
Neel
More information about the Python-list
mailing list