__str__ vs __repr__

Donn Cave donn at drizzle.com
Thu Jun 16 07:07:03 CEST 2005


Quoth "John Roth" <newsgroups at jhrothjr.com>:
...
| str() should be something that's meaningful to a human being when
| it's printed or otherwise rendered.

I can't believe how many people cite this explanation - meaningful,
friendly, pretty to a human being.  What on earth does this mean,
that couldn't be said more unambiguously?

According to my impression of common applications for Python programs,
rarely would anyone be looking at the output for esthetic gratification.
I mean, imagine your users casting an appraising eye over the contours
of a phrase emitted by the program, and praising the rhythmic effect of
the punctuation it chose to use, or negative space created by tabs.  heh.

Whether for human eyes or any destination, properly formed output will
carry the information that is required for the application, in a complete
and unambiguous way and in the format that is most readily processed,
and it will omit extraneous information.  Are we saying anything other
than this?

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list