Fwd: class print method...

Terry Reedy tjreedy at udel.edu
Mon Dec 5 14:55:01 EST 2011


On 12/5/2011 8:09 AM, Dave Angel wrote:

> useful, such as if you print a list. The __str__() method of list calls
> the __repr__() for each object inside it. So it can be useful to define
> both, even if you decide to have them do the same thing.

If you want __str__ and __repr__ to do the same thing, you only need 
*one* def statement and an assignment.

     def __str__(self): <whatever>
     __repr__ = __str__

-- 
Terry Jan Reedy




More information about the Python-list mailing list