Using __repr__ or __str__ for own printable class?

Greg Ewing (using ckea25d02 at
Mon Apr 14 08:00:19 CEST 2003

Mads Orbesen Troest wrote:
> The 
> documentation says __str__ is for the, quote, informal representation; 
> whereas __repr__ is for the, quote, official representation. Furthermore, 
> __reptr__ should, quote, look like an expression.

I don't find those guidelines particularly useful except
in fairly special cases. More generally, the rule of thumb
I use is that __str__ is for the "normal" output of the
program, whatever that might be, whereas __repr__ is for
debugging output.

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

More information about the Python-list mailing list