On 07/07/2014 22:11, Jan Kaliszewski wrote:
[snip]
IMHO, in Python context, "value" is a very vague term. Quite often we
can read it as the very basic (but not the only one) notion of "what
makes objects being equal or not" -- and then saying that "objects are
compared by value" is a tautology.
In other words, what object's "value" is -- is dependent on its
nature: e.g. the value of a list is what are the values of its
consecutive (indexed) items; the value of a set is based on values of
all its elements without notion of order or repetition; the value of a
number is a set of its abstract mathematical properties that determine
what makes objects being equal, greater, lesser, how particular
arithmetic operations work etc...
I think, there is no universal notion of "the value of a Python
object". The notion of identity seems to be most generic (every
object has it, event if it does not have any other property) -- and
that's why by default it is used to define the most basic feature of
object's *value*, i.e. "what makes objects being equal or not" (== and
!=). Another possibility would be to raise TypeError but, as Ethan
Furman wrote, it would be impractical (e.g. key-type-heterogenic dicts
or sets would be practically impossible to work with). On the other
hand, the notion of sorting order (< > <= >=) is a much more
specialized object property.
Quite so.
x, y = object(), object()
print 'Equal:', ' '.join(attr for attr in dir(x) if
getattr(x,attr)==getattr(y,attr))
print 'Unequal:', ' '.join(attr for attr in dir(x) if
getattr(x,attr)!=getattr(y,attr))
Equal: __class__ __doc__ __new__ __subclasshook__
Unequal: __delattr__ __format__ __getattribute__ __hash__ __init__
__reduce__ __reduce_ex__ __repr__ __setattr__ __sizeof__ __str__
Andreas, what attribute or combination of attributes do you think should
be the "values" of x and y?
Rob Cliffe
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com