id(a) == id(b) and a is not b --> bug?
gerrit at nl.linux.org
Fri Jun 6 21:43:36 CEST 2003
Erik Max Francis schreef op vrijdag 6 juni om 02:22:35 +0000:
> >>> class C:
> ... def m(self): pass
> >>> c = C()
> >>> c.m is c.m
> >>> id(c.m) == id(c.m)
> It's happening because accessing a method dynamically creates an unique
> object and goes away when you're finished with it.
There's probably a perfectly good reason for that ;)
> So when an
> expression needs both at the same time (c.m is c.m), two unique objects
> are created, but when an expression doesn't need both at the same time
> (id(c.m) == id(c.m)), an object gets created with an ID, is destroyed,
> and then a second object is created with the same ID (since the last one
> just got reclaimed) and their IDs compare equal. Weird, huh? (It
> surprised me when I first saw it, too.)
Ah, thanks for this explanation!
BTW, is there any way I could have found out about this myself, expect
reading the source (which I can't because of lack of knowledge)?
120. If any one store corn for safe keeping in another person's house,
and any harm happen to the corn in storage, or if the owner of the house
open the granary and take some of the corn, or if especially he deny that
the corn was stored in his house: then the owner of the corn shall claim
his corn before God (on oath), and the owner of the house shall pay its
owner for all of the corn that he took.
-- 1780 BC, Hammurabi, Code of Law
Asperger Syndroom - een persoonlijke benadering:
Het zijn tijden om je zelf met politiek te bemoeien:
More information about the Python-list