Using __repr__ or __str__ for own printable class?

Greg Ewing (using ckea25d02 at
Thu Apr 17 04:56:52 CEST 2003

Donn Cave wrote:
> But the idea that repr should be the function that conveys that
> "whole truth" is suspiciously consistent with the marshalling idea.

Just to clarify, I wasn't suggesting that the "whole
truth" idea should appy to __repr__ in general --
only that it seems to have been the motivation in
the particular case of floats.

In fact, for debugging output, the "whole truth"
is often far too MUCH information! An object with
a big complex data structure underneath is, I feel,
best __repr__'ed simply as <someobject at 0x12876ad>
rather than trying to print it all out somehow.

If I need to know more, I'll insert a debugging
print that prints out a bit more. I find print
someobj.__dict__ to be quite useful at times like

Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand

More information about the Python-list mailing list