Using __repr__ or __str__ for own printable class?

Donn Cave donn at u.washington.edu
Wed Apr 16 12:06:55 EDT 2003


Quoth "Greg Ewing (using news.cis.dfn.de)" <ckea25d02 at sneakemail.com>:
| 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.

But the idea that repr should be the function that conveys that
"whole truth" is suspiciously consistent with the marshalling idea.
Cf. following Tim Peters articles along those lines -
http://groups.google.com/groups?q=g:thl323609740d&dq=&hl=en&lr=&ie=UTF-8&selm=000001bf275c%2402370d20%241d2d153f%40tim
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=mailman.988673761.22305.python-list%40python.org

	Donn Cave, donn at u.washington.edu




More information about the Python-list mailing list