All, I propose that support for SI scale factors be added to Python. This would be very helpful for any program that heavily uses real numbers, such as those involved with scientific and engineering computation. There would be two primary changes. First, the lexer would be enhanced to take real literals with the following forms:
c1 = 1nF (same as: c1 = 1e-9 # F ) c = 299.79M (same as: c = 299.79e6 ) f_hy = 1.4204GHz (same as: f_hy = 1.4204e9 # Hz) Basically a scale factor and units may follow a number, both of which are optional, but if the units are given the scale factor must also be given. Any units given could be kept with the number and would be accessible through an attribute or method call, or if it is felt that the cost of storing the units are too high, it may simply be discarded, in which case it is simply serving as documentation. The second change would be to the various real-to-string conversions available in Python. New formatting options would be provided to support SI scale factors. For example, print('Hydrogen line frequency: %q' % f_hy) Hydrogen line frequency: 1.4204GHz If the units are retained with the numbers, then %q (quantity) could be used to print number with SI scale factors and units, and %r (real) could be used to print the number with SI scale factors but without the units. A small package that fleshes out these ideas is available from https://github.com/KenKundert/engfmt It used to be that SI scale factors were only used by scientists and engineers, but over the last 20 years their popularity has increased and so now they are used everywhere. It is time for our programming languages to catch up. I find it a little shocking that no programming languages offer this feature yet, but engineering applications such as SPICE and Verilog have supported SI scale factors for a very long time. -Ken _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/