confused about __str__ vs. __repr__

Tino Wildenhain tino at
Thu Dec 18 15:36:01 CET 2008

Neal Becker wrote:
>>> So if __str__ is "meant for human eyes", then why isn't print using it!
>> it is:
>>  > print x
>> str
>> but dict just uses repr() for all its childs to print.
>> T.
> That makes no sense to me.  If I call 'print' on a container, why wouldn't it recursively  print on the contained objects?  Since print means call str, printing a container should recursively call str on the objects.

Every class is free on how to best implement __str__, you will find
the same behavior on tuple and list as well.

Maybe its discussable to change the implementation sensibly, best if you
would come with a proposal? Perhaps pprint.pprint is a starting point?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <>

More information about the Python-list mailing list