Using __repr__ or __str__ for own printable class?

Greg Ewing (using news.cis.dfn.de) ckea25d02 at sneakemail.com
Mon Apr 14 02:00:19 EDT 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
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list