Using __repr__ or __str__ for own printable class?

Greg Ewing (using news.cis.dfn.de) ckea25d02 at sneakemail.com
Wed Apr 16 22:56:52 EDT 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
this.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list