[Python-ideas] real numbers with SI scale factors: next steps

Paul Moore p.f.moore at gmail.com
Wed Aug 31 03:00:42 EDT 2016


On 31 August 2016 at 05:08, Ken Kundert <python-ideas at shalmirane.com> wrote:
> Auto-scaling is kind of the point. There is really little need for a special
> mechanism if your going to specify the scale factor yourself.
>
>     >>> print('Attenuation = {:.1f} dB at {:r}m.'.format(-13.7, 50e3))
>     Attenuation = -13.7 dB at 50 km.
>
> If you wanted to force the second number to be in km, you use a %f format and
> scale the argument:
>
>     >>> print('Attenuation = {:.1f} dB at {:.1f} km.'.format(-13.7, 50e3/1e3))
>     Attenuation = -13.7 dB at 50 km.

This argument can just as easily be used against your proposal:

If you want auto-scaling you use a %s format and a suitable library function:

    >>> print('Attenuation = {:.1f} dB at {}m.'.format(-13.7, scale(50e3)))
    Attenuation = -13.7 dB at 50 km.

Anything that's going to be included in the language has to consider
other requirements than just your own.

> This is suddenly a much bigger project than what I was envisioning.

You're going to have to write the scaling code one way or the other.
Writing it in Python and publishing it as a library is *far* easier
than writing it in C and hooking it into the format mechanism. You can
leave others to offer pull requests to your library to add extra types
of formatting.

IMO, it's probably time to write some code. Publish a library on PyPI
(call it a "prototype" if you like) implementing the scale() function
above, publicise it here and elsewhere, and see what reception it
gets.

Paul


More information about the Python-ideas mailing list