Using __repr__ or __str__ for own printable class?

Beni Cherniavsky cben at techunix.technion.ac.il
Sun Apr 13 19:10:32 CEST 2003


Tim Peters wrote on 2003-04-12:

> OTOH, no type other than a string type seems to feel a pressing need for
> more than two convert-to-string gimmicks, and the basic container types
> don't even distinguish repr from str (str(list) and repr(list) act the same
> today because they are the same today).
>
Well, it is true that things will get confusing with strings.  But
when you do an str() of a list, how much do you care for it?  Perhaps
it's worth to apply str() in list.__str__, keeping list.__repr__ for
the cases when you need an unambiguos representation?  I.e. leve it up
to the user to decide whether he will be confused.

-- 
Beni Cherniavsky <cben at tx.technion.ac.il>

Never spend several weeks on a single homework - or you will miss a
nice Linux conference ;-(.





More information about the Python-list mailing list