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


Groups > comp.lang.python > #28480

Re: is implemented with id ?

Newsgroups comp.lang.python
Date 2012-09-05 05:48 -0700
References <franck-9EED34.08303005092012@news.free.fr> <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com>
Message-ID <b8c2c4dc-2afa-4921-bac1-1614e57c3e97@googlegroups.com> (permalink)
Subject Re: is implemented with id ?
From Ramchandra Apte <maniandram01@gmail.com>

Show all headers | View raw


On Wednesday, 5 September 2012 14:44:23 UTC+5:30, Steven D'Aprano  wrote:
> On Wed, 05 Sep 2012 08:30:31 +0200, Franck Ditter wrote:
> 
> 
> 
> > Hi !
> 
> > a is b <==> id(a) == id(b) in builtin classes. Is that true ?
> 
> 
> 
> Not just for builtin classes, for any objects, provided that they are 
> 

Seeing this thread, I think the is statment should be removed.
It has a replacement syntax of id(x) == id(y) and "a==True" should be automatically changed into memory comparison.
> alive at the same time.
> 
> 
> 
> There is no guarantee whether IDs will be re-used. Some versions of 
> 
> Python do re-use IDs, e.g. CPython:
> 
> 
> 
> steve@runes:~$ python
> 
> Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 
> 
> [GCC 4.4.5] on linux2
> 
> Type "help", "copyright", "credits" or "license" for more information.
> 
> >>> a = ["some", "object"]
> 
> >>> id(a)
> 
> 3074285228L
> 
> >>> del a
> 
> >>> b = [100, 200]
> 
> >>> id(b)
> 
> 3074285228L
> 
> 
> 
> but others do not, e.g. Jython and IronPython:
> 
> 
> 
> steve@runes:~$ jython
> 
> Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19) 
> 
> [OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18
> 
> Type "help", "copyright", "credits" or "license" for more information.
> 
> >>> a = ["some", "object"]
> 
> >>> id(a)
> 
> 1
> 
> >>> del a
> 
> >>> b = [100, 200]
> 
> >>> id(b)
> 
> 2
> 
> 
> 
> 
> 
> steve@runes:~$ ipy
> 
> IronPython 2.6 Beta 2 DEBUG (2.6.0.20) on .NET 2.0.50727.1433
> 
> Type "help", "copyright", "credits" or "license" for more information.
> 
> >>> a = ["some", "object"]
> 
> >>> id(a)
> 
> 43
> 
> >>> del a
> 
> >>> b = [100, 200]
> 
> >>> id(b)
> 
> 44
> 
> 
> 
> 
> 
> CPython especially has the most complicated behaviour with IDs and object 
> 
> identity: 
> 
> 
> 
> >>> a = 99.99
> 
> >>> b = 99.99
> 
> >>> a is b
> 
> False
> 
> >>> a = 99.99; b = 99.99; a is b 
> 
> True
> 
> 
> 
> 
> 
> In general, you almost never need to care about IDs and object identity. 
> 
> The main exception is testing for None, which should always be written as:
> 
> 
> 
>     if x is None
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

is implemented with id ? Franck Ditter <franck@ditter.org> - 2012-09-05 08:30 +0200
  Re: is implemented with id ? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2012-09-04 23:40 -0700
    Re: is implemented with id ? Franck Ditter <franck@ditter.org> - 2012-09-05 15:19 +0200
      Re: is implemented with id ? Hans Mulder <hansmu@xs4all.nl> - 2012-09-05 15:48 +0200
        Re: is implemented with id ? aahz@pythoncraft.com (Aahz) - 2012-11-03 12:41 -0700
          Re: is implemented with id ? Hans Mulder <hansmu@xs4all.nl> - 2012-11-03 22:49 +0100
            Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-03 22:18 +0000
              Re: is implemented with id ? Chris Angelico <rosuav@gmail.com> - 2012-11-04 09:50 +1100
              Re: is implemented with id ? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-04 01:14 +0000
                Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-04 03:10 +0000
                Re: is implemented with id ? Chris Angelico <rosuav@gmail.com> - 2012-11-04 14:19 +1100
                Re: is implemented with id ? aahz@pythoncraft.com (Aahz) - 2012-11-03 22:09 -0700
                Re: is implemented with id ? Hans Mulder <hansmu@xs4all.nl> - 2012-11-04 11:13 +0100
              Re: is implemented with id ? Chris Angelico <rosuav@gmail.com> - 2012-11-04 12:22 +1100
              Re: is implemented with id ? aahz@pythoncraft.com (Aahz) - 2012-11-03 22:08 -0700
            Re: is implemented with id ? Roy Smith <roy@panix.com> - 2012-11-03 18:41 -0400
            Re: is implemented with id ? aahz@pythoncraft.com (Aahz) - 2012-11-03 22:12 -0700
      Re: is implemented with id ? Dave Angel <d@davea.name> - 2012-09-05 10:00 -0400
        Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-05 14:41 +0000
          Re: is implemented with id ? Dave Angel <d@davea.name> - 2012-09-05 11:09 -0400
            Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-05 15:36 +0000
            Re: is implemented with id ? Hans Mulder <hansmu@xs4all.nl> - 2012-09-05 18:47 +0200
              Re: is implemented with id ? Dave Angel <d@davea.name> - 2012-09-05 13:19 -0400
          Re: is implemented with id ? Terry Reedy <tjreedy@udel.edu> - 2012-09-05 14:31 -0400
          Re: is implemented with id ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-05 22:08 -0400
          Re: is implemented with id ? Duncan Booth <duncan.booth@invalid.invalid> - 2012-09-06 09:34 +0000
            Re: is implemented with id ? Chris Angelico <rosuav@gmail.com> - 2012-09-06 19:50 +1000
          Re: is implemented with id ? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-11-04 01:33 -0700
  Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-05 09:14 +0000
    Re: is implemented with id ? Ramchandra Apte <maniandram01@gmail.com> - 2012-09-05 05:48 -0700
      Re: is implemented with id ? Dave Angel <d@davea.name> - 2012-09-05 09:46 -0400
      Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-05 14:13 +0000
        Re: is implemented with id ? Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-05 11:08 -0600
        Re: is implemented with id ? Chris Angelico <rosuav@gmail.com> - 2012-09-06 19:07 +1000
      Re: is implemented with id ? Terry Reedy <tjreedy@udel.edu> - 2012-09-05 14:27 -0400
        Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-06 06:44 +0000
          Re: is implemented with id ? Ramchandra Apte <maniandram01@gmail.com> - 2012-09-06 01:24 -0700
          Re: is implemented with id ? Roy Smith <roy@panix.com> - 2012-09-06 08:16 -0400
            Re: is implemented with id ? Ramchandra Apte <maniandram01@gmail.com> - 2012-09-06 06:30 -0700
      Re: is implemented with id ? Dave Angel <d@davea.name> - 2012-09-05 14:40 -0400

csiph-web