Using __repr__ or __str__ for own printable class?
Erik Max Francis
max at alcyone.com
Mon Apr 14 05:09:37 EDT 2003
Alex Martelli wrote:
> There's supposed to be a good reason for this to print [rep],
> rather than [str] as common sense would suggest, but I keep
> forgetting it (so it's probably nor very compelling;-).
I have to agree. It makes more sense to me that the str of a collection
prints the str of its elements (and on down), and that the repr of a
collection prints the repr of its elements. That isn't the way things
work, and I accept that and it's not a huge issue for me, but I
personally consider it one of Python's minor quirks. I can see the
argument (which was put forth in this thread) that printing the str
might be misleading in some cases, but that doesn't seem to me a very
compelling argument; since both the str and repr are user-selectable, it
should be easy for an inquisitive soul who's confused about what he's
seeing to figure out what's going on with little or no trouble.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ Bachelors have consciences, married men have wives.
\__/ H.L. Mencken
WebVal / http://www.alcyone.com/pyos/webval/
URL scanner, maintainer, and validator in Python.
More information about the Python-list
mailing list