[ python-Feature Requests-1534942 ] Print identical floats consistently

SourceForge.net noreply at sourceforge.net
Wed Aug 9 22:35:22 CEST 2006


Feature Requests item #1534942, was opened at 2006-08-05 06:19
Message generated for change (Comment added) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1534942&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.6
Status: Open
Resolution: None
Priority: 5
Submitted By: Marc W. Abel (gihon)
Assigned to: Nobody/Anonymous (nobody)
Summary: Print identical floats consistently

Initial Comment:
Hello again and thank you,

This is a rewrite of now-closed bug #1534769.

As you know, 

>>> print .1
>>> print (.1,)

give different results because the __str__ call from
print becomes a __repr__ call on the tuple, and it
stays a __repr__ beneath that point in any recursion. 
>From the previous discussion, we need behavior like
this so that strings are quoted inside tuples.

I suggest that print use a third builtin that is
neither __str__ nor __repr__.  The name isn't
important, but suppose we call it __strep__ in this
feature request.  __strep__ would pass __strep__ down
in the recursion, printing floats with __str__ and
everything else with __repr__.

This would then

>>> print .1                and
>>> print (.1,)

with the same precision.

Marc


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

>Comment By: Georg Brandl (gbrandl)
Date: 2006-08-09 20:35

Message:
Logged In: YES 
user_id=849994

I recommend closing this. Introducing yet another to-string
magic function is not going to make things simpler, and who
knows if the str/repr distinction is going to make it into
3.0 anyway.

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

Comment By: Josiah Carlson (josiahcarlson)
Date: 2006-08-09 16:14

Message:
Logged In: YES 
user_id=341410

Please note that 'print non_string' is a convenience.  Its
output is neither part of the language spec, nor is the
propagation of str/repr calls.

If you want to control how items are formatted during print,
you should use the built-in string formatting mechanisms. 
The standard 'print "%.1f"%(.1,)' and 'print
"%(x).1f"%({x:.1})' works with all pythons, and there is an
updated templating mechanism available in more recent Python
versions.

I'm not the last word on this, but I don't see an actual
use-case that isn't satisfied by using built-in
string-formatting.

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1534942&group_id=5470


More information about the Python-bugs-list mailing list