Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev

[format] Restrict fill characters for numerical values

 

 

Python dev RSS feed   Index | Next | Previous | View Threaded


stefan-usenet at bytereef

Nov 11, 2009, 3:36 AM

Post #1 of 5 (334 views)
Permalink
[format] Restrict fill characters for numerical values

Hi,

I think http://www.python.org/dev/peps/pep-3101/ is too liberal with the
choice of fill characters for numerical values. As far as I can see, this
is quite legal:


Python 2.7a0 (trunk:76132M, Nov 6 2009, 15:20:35)
[GCC 4.1.3 20080623 (prerelease) (Ubuntu 4.1.2-23ubuntu3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import *
>>> format(Decimal(4), "9<10")
'4999999999'
>>> format(Decimal(4), "9>10")
'9999999994'
>>> format(Decimal(4), "->2")
'-4'
>>>


I propose to disallow digits and '+-' fill characters for numerical values,
except for the combination '0, left-padding'. Actually, I'd prefer to allow
only whitespace and '0, left-padding'.


See also:

http://bugs.python.org/issue6871
http://bugs.python.org/issue6902



Stefan Krah


_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


eric at trueblade

Nov 11, 2009, 4:39 AM

Post #2 of 5 (315 views)
Permalink
Re: [format] Restrict fill characters for numerical values [In reply to]

Stefan Krah wrote:
> Hi,
>
> I think http://www.python.org/dev/peps/pep-3101/ is too liberal with the
> choice of fill characters for numerical values. As far as I can see, this
> is quite legal:
>
>
> Python 2.7a0 (trunk:76132M, Nov 6 2009, 15:20:35)
> [GCC 4.1.3 20080623 (prerelease) (Ubuntu 4.1.2-23ubuntu3)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from decimal import *
>>>> format(Decimal(4), "9<10")
> '4999999999'
>>>> format(Decimal(4), "9>10")
> '9999999994'
>>>> format(Decimal(4), "->2")
> '-4'
>
>
> I propose to disallow digits and '+-' fill characters for numerical values,
> except for the combination '0, left-padding'. Actually, I'd prefer to allow
> only whitespace and '0, left-padding'.

Why?

What problem are you trying to prevent that would justify the extra code
to implement this and the extra documentation to explain it?

Eric.
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


stefan-usenet at bytereef

Nov 11, 2009, 5:06 AM

Post #3 of 5 (315 views)
Permalink
Re: [format] Restrict fill characters for numerical values [In reply to]

Eric Smith <eric [at] trueblade> wrote:
> Stefan Krah wrote:
> >Hi,
> >
> >I think http://www.python.org/dev/peps/pep-3101/ is too liberal with the
> >choice of fill characters for numerical values. As far as I can see, this
> >is quite legal:
> >
> >
> >Python 2.7a0 (trunk:76132M, Nov 6 2009, 15:20:35)
> >[GCC 4.1.3 20080623 (prerelease) (Ubuntu 4.1.2-23ubuntu3)] on linux2
> >Type "help", "copyright", "credits" or "license" for more information.
> >>>>from decimal import *
> >>>>format(Decimal(4), "9<10")
> >'4999999999'
> >>>>format(Decimal(4), "9>10")
> >'9999999994'
> >>>>format(Decimal(4), "->2")
> >'-4'
> >
> >
> >I propose to disallow digits and '+-' fill characters for numerical values,
> >except for the combination '0, left-padding'. Actually, I'd prefer to allow
> >only whitespace and '0, left-padding'.
>
> Why?
>
> What problem are you trying to prevent that would justify the extra code
> to implement this and the extra documentation to explain it?


I simply think that apart from rounding, the output of format should not
change the numerical value of its argument. The format functions in C do
not allow this to happen. Are there other languages where this is possible?


Stefan Krah


_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


stefan-usenet at bytereef

Nov 11, 2009, 5:34 AM

Post #4 of 5 (315 views)
Permalink
Re: [format] Restrict fill characters for numerical values [In reply to]

Stefan Krah <stefan-usenet [at] bytereef> wrote:
> I simply think that apart from rounding, the output of format should not
> change the numerical value of its argument. The format functions in C do
> not allow this to happen. Are there other languages where this is possible?

Actually there are other cases: strfmon() allows this, too. Let's drop it.


Stefan Krah


_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


eric at trueblade

Nov 11, 2009, 6:11 AM

Post #5 of 5 (314 views)
Permalink
Re: [format] Restrict fill characters for numerical values [In reply to]

Stefan Krah wrote:
> Eric Smith <eric [at] trueblade> wrote:
>> Stefan Krah wrote:
>>> Hi,
>>>
>>> I think http://www.python.org/dev/peps/pep-3101/ is too liberal with the
>>> choice of fill characters for numerical values. As far as I can see, this
>>> is quite legal:
>>>
>>>
>>> Python 2.7a0 (trunk:76132M, Nov 6 2009, 15:20:35)
>>> [GCC 4.1.3 20080623 (prerelease) (Ubuntu 4.1.2-23ubuntu3)] on linux2
>>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> >from decimal import *
>>>>>> format(Decimal(4), "9<10")
>>> '4999999999'
>>>>>> format(Decimal(4), "9>10")
>>> '9999999994'
>>>>>> format(Decimal(4), "->2")
>>> '-4'
>>>
>>>
>>> I propose to disallow digits and '+-' fill characters for numerical values,
>>> except for the combination '0, left-padding'. Actually, I'd prefer to allow
>>> only whitespace and '0, left-padding'.
>> Why?
>>
>> What problem are you trying to prevent that would justify the extra code
>> to implement this and the extra documentation to explain it?
>
>
> I simply think that apart from rounding, the output of format should not
> change the numerical value of its argument. The format functions in C do
> not allow this to happen. Are there other languages where this is possible?

I don't know if there are other languages that allow it. But I
definitely have use cases for padding with '*', for example. I don't see
the point in just disallowing numbers 1 through 9. If you don't want
your numbers padded with 9's, don't put a 9 in your format string.

Eric.

_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com

Python dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.