confused about __str__ vs. __repr__
Tino Wildenhain
tino at wildenhain.de
Thu Dec 18 09:14:34 EST 2008
Neal Becker wrote:
> Reading some FAQ, I see that __str__ is "meant for human eyes".
>
> But it seems that:
> class X(object):
> def __str__(self):
> return "str"
> def __repr__(self):
> return "repr"
>
> x = X()
> d = {0 : x}
> print d
> {0: repr}
>
> 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.
-------------- 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: <http://mail.python.org/pipermail/python-list/attachments/20081218/02eeb5d2/attachment-0001.bin>
More information about the Python-list
mailing list