[Python-Dev] format specification mini-language docs...
eric at trueblade.com
Sat Nov 22 03:03:43 CET 2008
Dino Viehland wrote:
> Ok, now I'm implementing __format__ support for IronPython. The format spec mini-language docs say that a presentation type of None is the same as 'g' for floating point / decimal values.
Awesome! Thanks for doing this.
>But these two formats seem to differ based upon how they handle whole
I think the docs are wrong. For floats, the PEP
'' (None) - similar to 'g', except that it prints at least one digit
after the decimal point.
> The docs also say that 'g' prints it as fixed point unless the number is too large. But the fixed point format differs from what 'f' would print. I guess it didn't say they'd both print it as fixed point w/ a precision of 6 or anything but it seems a little unclear.
This is to be compatible with %-formatting:
Python 2.7a0 (trunk:67325, Nov 21 2008, 20:35:33)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> '%f %g' % (2.0, 2.0)
> Finally providing any sign character seems to cause +1.0#INF and friends to be returned instead of inf as is documented:
Yes, that does seem odd. Let me look at it a bit and I'll comment on it,
hopefully this weekend. I have a pending fix for 2.7/3.1 to make inf
handling more consistent across platforms, it might take care of this
> Are these just doc bugs? The inf issue is the only one that seems particularly weird to me.
More information about the Python-Dev