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

David Murmann david.murmann at rwth-aachen.de
Thu Jan 12 20:53:32 EST 2006


rurpy at yahoo.com schrieb:
> "Fredrik Lundh" <fredrik at pythonware.com> wrote in message
>> *what* the value is is defined by the operations that the object supports (via its
>> type).
> 
> Well, that is already better than what is in the Lang Ref.
> But there must be more to it than that.  int(1) and int(2)
> have exactly the same operations, yes?  Yet their values
> are different.  (By "operations" you mean the set of methods
> an object has?)

well, yes, but the behavior of the operations of an object are
based on its value. and in python you have no other possibility
to get closer to an objects value than to look what its methods
do (in the case of an int, print it, compare it, etc.). that
means the whole concept of a value is not really necessary to be
able to write a python program.

> 1. Do all objects have values?
> 2. What is the value of object()?

i'd say these two are closely related, and i'd say yes, all objects
have values and you can't really tell what the value of an object() is.
what you can say is, that two object()s have different values, because
their behavior differs (id(object)!).

but, one could define that id() is a special case and does not
contribute to the behavior of an object, so that different int
objects that print the same really have the same value.

> 3. If two objects are equal with "==", does that
>   mean their values are the same?

no, absolutely not. think this class:

class C(object):
    def __eq__(self, other):
        return True

> 4. Are object attributes part of an object's type
>   or it's value, or something else?  (I think the first.)

they are part of an objects operations, just a shorthand for
__getattr__ and __setattr__.

> 5. The (only?) way to get an object's value is to
>   evaluate something (a name or a "reference"(*)
>   that refers to the object.

there is no such way (at least not to my knowledge).
at least not in general. of course you can print an int
and "see" its value, but you could define a C extension type
which holds a whole bunch of things as its value that are
completely inaccessible from python (are they then even part
of such an objects value? i don't care, its no use to define
"value" in either way).

i hope i did not confuse more than clarify, but this is the way
i see it.

also note that i understood Fredrik's quote from above in exactly
this way, this is just meant to clarify. (so please correct me if
i'm wrong)

--
David.



More information about the Python-list mailing list