Best practise implementation for equal by value objects
Terry Reedy
tjreedy at udel.edu
Thu Aug 7 15:19:26 EDT 2008
Slaunger wrote:
> On 6 Aug., 21:36, Terry Reedy <tjre... at udel.edu> wrote:
> OK, the situation is more complicated than that then. In the case here
> though,
> the attributes would always be sinmple bulit-in types, where
> eval(repr(x))==x
> or, where the attribute is a user-defined equal-by-value class, that I
> have
> control over.
I think most would agree that a more accurate and informative
representation is better than a general representation like Pythons
default. For instance,
>>> a=range(2,10,2) # 3.0
>>> a
range(2, 10, 2)
is nicer than <class 'range' object at ######>.
So when the initializers for instances are all 'nice' (as for range), go
for it (as in 'Age(10)'). And test it as you are by eval'ing the rep.
Just accept that the eval will only work in contexts with the class name
bound to the class. For built-in like range, it always is, by default
-- unless masked by another assignment!
Terry Jan Reedy
More information about the Python-list
mailing list