On Wed, Aug 31, 2016, at 12:19, Guido van Rossum wrote: > On Wed, Aug 31, 2016 at 5:21 AM, Nick Coghlan <ncogh...@gmail.com> wrote: > > "h" would be a decent choice - it's not only a continuation of the > > e/f/g pattern, it's also very commonly used as a command line flag for > > "human-readable output" in system utilities that print numbers. > > I like it. So after all the drama we're just talking about adding an > 'h' format code that's like 'g' but uses SI scale factors instead of > exponents. I guess we need to debate what it should do if the value is > way out of range of the SI scale system -- what's it going to do when > I pass it 1e50? I propose that it should fall back to 'g' style then, > but use "engineering" style where exponents are always a multiple of > 3.)
One thing to consider is that this is very likely to be used with a unit (e.g. "%hA" intending to display in amperes), so maybe it should put a space after it? Though really people are probably going to want "1 A" vs "1 kA" in that case, rather than "1 A" vs "1kA". Also, maybe consider that "1*10^50" [or, slightly less so, 1.0*10**50] is more human-readable than "1e+50". Er, with engineering style it'd be 100e+48 etc, but same basic issue. Also, is it really necessary to use single-character codes not shared with any other language? The only rationale here seems to be a desire to support everything in % and its limited grammar rather than requiring anyone to use format. If this feature is only supported in format a more verbose description of the desired format could be used. What if, for example, you want engineering style without SI scale factors? What should the "precision" field mean? %f takes a number of places after the decimal point whereas %e/%g takes a number of significant digits. Engineering or SI-scale-factor format suggests a third possibility: number of decimal places to be shown after the displayed decimal point, e.g. "%.1h" % 1.2345 * 10 ** x for x in range(10): "1.2", "12.3", "123.5", "1.2k", "12.3k", "123.5k", "1.2M", "12.3M", "123.5M". And the actual -h behavior of those system utilities you mentioned is "123k", "1.2M", "12M", with the effect being that the value always fits within a four-character field width, but this isn't a fixed number of decimal places *or* significant digits. > > The existing "alternate form" marker in string formatting could be > > used to request the use of the base 2 scaling prefixes rather than the > > base 10 ones: "#h". If base 2 scaling prefixes are used, should "engineering style" mean 2**[multiple of 10] instead of 10**[multiple of 3]? > Not sure about this one. _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/