Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42848

Re: is operator versus id() function

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <timothy.c.delaney@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'win32': 0.03; 'cpython': 0.05; 'method.': 0.07; 'reason,': 0.07; 'bug.': 0.09; 'instances.': 0.09; 'method,': 0.09; 'snippet': 0.09; 'python': 0.11; 'def': 0.12; 'a(object):': 0.16; 'subject:versus': 0.16; 'unbound': 0.16; 'unexpected': 0.16; '\xc3\xa9crit\xc2\xa0:': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'value.': 0.19; '>>>': 0.22; '&gt;&gt;&gt;': 0.24; 'integer': 0.24; 'fairly': 0.24; '&gt;': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'skip:p 30': 0.29; 'tim': 0.29; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'code': 0.31; 'constant': 0.31; 'doc': 0.31; 'object.': 0.31; 'sep': 0.31; 'class': 0.32; 'url:python': 0.33; 'could': 0.34; 'created': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'accessing': 0.36; 'false': 0.36; 'method': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'two': 0.37; 'skip:& 10': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'explain': 0.39; 'skip:& 20': 0.39; 'to:addr:python.org': 0.39; 'read': 0.60; 'url:3': 0.61; "you've": 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'different': 0.65; 'here': 0.66; 'answer.': 0.68; 'guaranteed': 0.75; 'accessed.': 0.84; 'victim': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=UX/hzL3vopC8dNbnJlCpoW1Guh1FRJ1dB/PnSWrxVj8=; b=lVb69ygEHCS/lex+m6bY7IPZRaSUSX3AB3UdseYjqSuewilsKe3f9M6oDRbZrtq5YQ Z4OVA/eHuTjOAfHYF6717p9TKt4tdLITnAhRIFzPPEjfgkn7iZWmjm9m3gynFAF6VeKs 9Gk8wbcnSgHwriz9JyKB3n6LjHV8S2ASDwGu4/b7mrr/ICqsxmUus/mQCpQm5QDfBCn7 fw4ggzKN6QhEgP6f82jxBMx/V8PgJbQXWYO/8+HXWF/PiBw2vZVXoob9VDtgOzF8Mwmi PWgygYYymdVnYYnl9E4UoMfuEVI4D3qt5v76o56ANPc3ADxctWwvWluVWYgGD/Shpovs Y5lA==
MIME-Version 1.0
X-Received by 10.60.37.68 with SMTP id w4mr9088150oej.62.1365191821362; Fri, 05 Apr 2013 12:57:01 -0700 (PDT)
In-Reply-To <e120252a-22c1-4e4c-9e87-42974a6082ad@googlegroups.com>
References <ed17e4ac-2000-42ef-aa2b-69ff421ae3fa@googlegroups.com> <mailman.144.1365173642.3114.python-list@python.org> <e120252a-22c1-4e4c-9e87-42974a6082ad@googlegroups.com>
Date Sat, 6 Apr 2013 06:57:01 +1100
Subject Re: is operator versus id() function
From Tim Delaney <timothy.c.delaney@gmail.com>
To Python <python-list@python.org>
Content-Type multipart/alternative; boundary=089e0111c130900ef404d9a27d0b
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.160.1365191829.3114.python-list@python.org> (permalink)
Lines 100
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365191830 news.xs4all.nl 6860 [2001:888:2000:d::a6]:35546
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:42848

Show key headers only | View raw


[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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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