str() of a tuple
Douglas Zongker
dougz at cs.washington.edu
Wed Sep 4 17:24:54 EDT 2002
I'm sure this is a FAQ, but I haven't found a good explanation for one
of Python's most irritating behaviors:
>>> a = -0.4
>>> repr(a)
'-0.40000000000000002'
>>> str(a)
'-0.4'
So far, so good.
>>> b = (a,)
>>> repr(b)
'(-0.40000000000000002,)'
>>> str(b) # argggh.
'(-0.40000000000000002,)'
Why, oh why does the str() of a container use the repr()s of the
objects inside? This seems to violate what the docs claim str() does
-- "return a nicely printable representation of an object." Would a
sane implementation break something?
Is there a convenient way to print out a tuple of floats so that the
output is actually readable?
thanks,
dz
More information about the Python-list
mailing list