Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42848
| References | <ed17e4ac-2000-42ef-aa2b-69ff421ae3fa@googlegroups.com> <mailman.144.1365173642.3114.python-list@python.org> <e120252a-22c1-4e4c-9e87-42974a6082ad@googlegroups.com> |
|---|---|
| Date | 2013-04-06 06:57 +1100 |
| Subject | Re: is operator versus id() function |
| From | Tim Delaney <timothy.c.delaney@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.160.1365191829.3114.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On 6 April 2013 03:40, candide <c.candide@laposte.net> wrote:
> Le vendredi 5 avril 2013 16:53:55 UTC+2, Arnaud Delobelle a écrit :
>
>
> >
> > You've fallen victim to the fact that CPython is very quick to collect
> >
> > garbage.
>
>
> OK, I get it but it's a fairly unexpected behavior.
> Thanks for the demonstrative snippet of code and the instructive answer.
>
If you read the docs for id() <
http://docs.python.org/3.3/library/functions.html#id>, you will see that it
says:
Return the "identity" of an object. This is an integer which is guaranteed
to be unique and constant for this object during its lifetime. Two objects
with non-overlapping lifetimes may have the same id() value.
If you think it could explain things better, please submit a doc bug.
I think part of your confusion here is that bound methods in Python are
created when accessed. So A.f and a.f are not the same object - one is a
function (an unbound method, but there's no distinction in Python 3.x) and
the other is a bound method. For that reason, accessing a.f twice will
return two different bound method instances.
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A(object):
... def f(self):
... print("A")
...
>>> a=A()
>>> print(id(a.f) == id(a.f), a.f is a.f)
True False
>>>
Tim Delaney
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
is operator versus id() function Candide Dandide <c.candide@laposte.net> - 2013-04-05 06:49 -0700
Re: is operator versus id() function Arnaud Delobelle <arnodel@gmail.com> - 2013-04-05 15:53 +0100
Re: is operator versus id() function candide <c.candide@laposte.net> - 2013-04-05 09:40 -0700
Re: is operator versus id() function Tim Delaney <timothy.c.delaney@gmail.com> - 2013-04-06 06:57 +1100
Re: is operator versus id() function candide <c.candide@laposte.net> - 2013-04-05 09:40 -0700
Re: is operator versus id() function Nobody <nobody@nowhere.com> - 2013-04-06 14:35 +0100
csiph-web