Thank you for the advice.
Actually, what annoys me is that list textual output, either with print or
str(), calls repr() for each item of the list, instead of str(). That's why I
had these strange things with floats, as illustrated in my first post on the topic:
class Seq(list):
''' se
On Fri, 14 Nov 2008 15:21:17 +0100, spir wrote:
> Well, actually not really I guess. I asked for rounded floats, not
> full-precision ones.
> Now, after more reflexion on the topic, I understand that even rounded
> floats need to keep full precision internally, because of the 'modular'
> difference
A.T.Hofkamp a écrit :
> spir wrote:
>> # By the way, I do not understand at all the behaviour of repr on
>> rounded floats:
>> x = round(1.1,1)
>> print x, repr(x), "%s" %x
>> 1.1 1.1001 1.1
>
> This is a FAQ question:
>
>
http://www.python.org/doc/faq/general/#why-are-floating-point-
[addendum]
Well, actually, the previous Seq didn't solve all problems. Obvious case of
nested lists. Below a modified version.
denis
class Seq(list):
''' specialized sequence type with improved str
Override list's behaviour that str(list) calls repr instead of
str on it
spir wrote:
# By the way, I do not understand at all the behaviour of repr on
rounded floats:
x = round(1.1,1)
print x, repr(x), "%s" %x
1.1 1.1001 1.1
This is a FAQ question:
http://www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate
Sincerely,
Albe
Below an illustration of what troubles me a bit.
denis
class Seq(list):
''' specialized sequence type with improved str
Override list's behaviour that list.__str__
calls __repr__ instead of __str__ on items.
???
'''
def __str__(self):