Is 'everything' a refrence or isn't it?

Fredrik Lundh fredrik at pythonware.com
Fri Jan 13 06:25:33 EST 2006


Sybren Stuvel wrote:

> Mike Meyer enlightened us with:
> >> I think type 'object' has only one value, so that's it.
> >
> > In that case, they should all be equal, right?
> >
> >>>> object() == object()
> > False
>
> You compare instances of the type 'object'. They both have one value:
>
> >>> object()
> <object object at 0xb7ddb438>
> >>> object()
> <object object at 0xb7ddb440>
>
> So the claim "type 'object' has only one value" is true. It's just not
> the same value for all instances.

You're comparing identities, not values.  The value is the set of things that
you can access via an object's methods (via the type).  The identity is not,
in itself, a part of the value.

Python doesn't query the object to determine it's type or identity, but it
always has to query the object to access the value.

A look at the C implementation of a typical object might help:

    typedef struct {
        int ob_refcnt;
        struct _typeobject *ob_type; /* type */
        ... an unknown amount of stuff used to represent the value ...
    } MyObject;

In CPython, the MyObject* pointer is the identity.  The ob_refcnt field is a
CPython implementation detail.  The ob_type field contains the type.  The
rest of the structure is known only by the MyObject type implementation.

</F>






More information about the Python-list mailing list