__str__ vs. __repr__
da at ski.org
Thu Nov 4 05:58:22 CET 1999
On Wed, 3 Nov 1999, Guido van Rossum wrote:
> Any suggestions?
I certainly appreciate the justification for the current behavior, which I
didn't really understand either.
I have two suggestions which would make the current read-eval-print
behavior somewhat more palatable to me:
-- container types (lists, dicts, tuples) should have both repr and str
methods, even if they differ only in the methods of the contents that
they call. You can make the str methods use the repr-type display
(with brackets/parens/braces and commas), as that wouldn't break
anyone's expectations (since that's what is currently being used), and
would 'solve' the current inconsistency.
I understand str output is meant to be human readable -- that
doesn't mean that 's and ,'s can't be used.
-- make the str of a long integer not have the postfix L. After all, if
the __str__ is supposed to be for human consumption, the L is no more
useful than the quotes around strings.
The issue of determining the printability of characters is one *I*
wouldn't touch with a 10-foot snake.
More information about the Python-list