[Python-bugs-list] [ python-Bugs-506741 ] ugly floats using str() on tuples,lists

noreply@sourceforge.net noreply@sourceforge.net
Tue, 22 Jan 2002 23:52:44 -0800


Bugs item #506741, was opened at 2002-01-21 17:53
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=506741&group_id=5470

Category: Python Interpreter Core
Group: Python 2.1.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Tim Wegener (twegener)
Assigned to: Nobody/Anonymous (nobody)
Summary: ugly floats using str() on tuples,lists

Initial Comment:
Python version 2.1.1
Using str() to make floats look pretty works for 
str(some_float_variable), but for 
str(tuple_of_floats) the output floats are still 
ugly. 

In Python 2.1.1:
>>> a=1.9
>>> a
1.8999999999999999
>>> str(a)
'1.9'
>>> (a,a)
(1.8999999999999999, 1.8999999999999999)
>>> str((a,a))
'(1.8999999999999999, 1.8999999999999999)'
>>> [a,a]
[1.8999999999999999, 1.8999999999999999]
>>> str([a,a])
'[1.8999999999999999, 1.8999999999999999]'
>>>

In Python 1.5.2
>>> a=1.9
>>> str(a)
'1.9'
>>> str((a,a))
'(1.9, 1.9)'
>>> str([a,a])
'[1.9, 1.9]'
>>>



----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2002-01-22 23:52

Message:
Logged In: YES 
user_id=21627

This is not a bug. If you want to format objects in a
certain non-standard way, you must write your own algorithm
to do so. See pprint.py for an example.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=506741&group_id=5470