Using __repr__ or __str__ for own printable class?

Greg Ewing (using news.cis.dfn.de) ckea25d02 at sneakemail.com
Tue Apr 15 18:50:21 EDT 2003


Donn Cave wrote:
> The idea that repr() must marshal the object is a sorely misguided
> extension of this.  It is not consistently supported enough to be
> clearly useful, and it has done some harm, e.g., it apparently
> contributed to a move to make the repr for floats to display full
> precision.

No, I think the reason for that is to provide something
which can be relied upon to tell you the "whole truth"
about the value of a float; str(aFloat) lies to you slightly,
exacerbating people's confusion about the behaviour of
float arithmetic.

Of course, it's still not *quite* the whole truth --
to get that you'd have to display it in binary.
But it's better than it used to be.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list