confused about __str__ vs. __repr__
tino at wildenhain.de
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
>> but dict just uses repr() for all its childs to print.
> 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...
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
More information about the Python-list