obj in list and list ids the same
rdudfield at my-deja.com
rdudfield at my-deja.com
Wed Dec 29 01:58:57 EST 1999
In article <84btoo$mem$1 at nntp.Stanford.EDU>,
amitp at Xenon.Stanford.EDU (Amit Patel) wrote:
> <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.
>
> It is odd.
>
> Here's how it could happen:
>
> >>> a = []
> >>> a.append(a)
>
> >>> id(a)
> 135070976
>
> >>> id(a[0])
> 135070976
>
> Let's try printing this:
>
> >>> a
> [[...]]
>
> The list has a pointer to itself. I'm not sure if this is the same
> problem you're seeing, but you might poke around to see if you're
> accidentally using some list instead of some list[some index].
>
Looks like I was doing something wrong for the id. After a nights sleep I
found it in the morning. Thanks for the help Laurence and Amit :)
It seems that deepcopy doesn't work for what I am doing. That is tempNode =
copy.deepcopy(self) because tempNode.value[0].listOfShapes and
self.value[0].listOfShapes have the same id. I guess this is reasonable. So
I just manually copy the list with a new one, not too hard now that I know :)
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list