Pointer or unique id

Discussion in 'Python' started by Nomak, Jan 15, 2005.

  1. Nomak

    Nomak Guest

    Hello,

    does python have an equivalent to Java: int Object.hashCode() ?

    TIA
    --
    Nomak
     
    Nomak, Jan 15, 2005
    #1
    1. Advertising

  2. Nomak a écrit :
    > Hello,
    >
    > does python have an equivalent to Java: int Object.hashCode() ?
    >


    id(object) -> integer
    Return the identity of an object. This is guaranteed to be unique among
    simultaneously existing objects. (Hint: it's the object's memory address.)

    hash(obj) -> integer
    Return a hash value for the object. Two objects with the same value
    have the same hash value. The reverse is not necessarily true, but likely.

    HTH
    Bruno
     
    Bruno Desthuilliers, Jan 15, 2005
    #2
    1. Advertising

  3. Bruno Desthuilliers wrote:

    > hash(obj) -> integer
    > Return a hash value for the object. Two objects with the same value
    > have the same hash value. The reverse is not necessarily true, but likely.


    Of course not all Python objects are hashable:

    >>> hash([])

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    TypeError: list objects are unhashable
    --
    Michael Hoffman
     
    Michael Hoffman, Jan 15, 2005
    #3
  4. Nomak

    Terry Reedy Guest

    "Bruno Desthuilliers" <> wrote in
    message news:41e94d40$0$29202$...
    >id(object) -> integer
    >Return the identity of an object. This is guaranteed to be unique among
    >simultaneously existing objects.


    This is part of the language specification. Also, the identity of an
    object must remain the same for its entire lifetime.

    > (Hint: it's the object's memory address.)


    This is an implementation detail of CPython. It cannot be true if the
    garbage collector moves objects around. Or if the object lives elsewhere
    (and is accessed thru a proxy).

    Terry J. Reedy
     
    Terry Reedy, Jan 15, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    705
    Chris Torek
    Feb 4, 2005
  2. jimjim
    Replies:
    16
    Views:
    844
    Jordan Abel
    Mar 28, 2006
  3. ToshiBoy
    Replies:
    6
    Views:
    853
    ToshiBoy
    Aug 12, 2008
  4. Replies:
    4
    Views:
    1,270
    Fred Zwarts
    Jul 2, 2009
  5. Token Type
    Replies:
    9
    Views:
    361
    Chris Angelico
    Sep 9, 2012
Loading...

Share This Page