[Python-Dev] [format] Restrict fill characters for numerical values

Stefan Krah stefan-usenet at bytereef.org
Wed Nov 11 14:06:34 CET 2009


Eric Smith <eric at trueblade.com> 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




More information about the Python-Dev mailing list