On Mon, Jan 20, 2020 at 09:59:07PM -0600, Karl O. Pinc wrote:
It would be nice if the output format for float was documented, to the extent this is possible.
I don't think we should make any promises about the repr() of floats. We've already changed the format at least twice: - once to switch to the shortest unambiguous representation; - and once to shift to a more consistent output for NANs. (NANs on Windows prior to 2.6 used to be displayed as '1.#IND', if I recall correctly.) We may never want to change output format again, but if we document a certain format that will be read by people as a guarantee, and that closes the door to any change without a long and tedious deprecation period. If anyone wants a guaranteed output format for floats, they ought to use the various string formatting operations, which offer guaranteed formatting outputs. Or build your own formatter. I think that the most we should promise is that (with the exception of NANs) float -> repr -> float should round-trip with no change in value.
I don't really care whether there's documentation for __str__() or __repr__() or something else. I'm just thinking that there should be some way to guarantee a well defined "useful" float output formatting.
https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatti... https://docs.python.org/3/library/string.html#format-string-syntax -- Steven