[Python-ideas] SI scale factors in Python

Chris Angelico rosuav at gmail.com
Sat Aug 27 15:22:54 EDT 2016


On Sun, Aug 28, 2016 at 4:25 AM, Steven D'Aprano <steve at pearwood.info> wrote:
>
> Sympy (apparently) doesn't warn you if your units are incompatible, it
> just treats them as separate terms in an expression:
>
> py> 2*m + 3*K
> 3*K + 2*m
>
> which probably makes sense from the point of view of a computer algebra
> system (adding two metres and three degrees Kelvin is no weirder than
> adding x and y). But from a unit conversion point of view, I think
> sympy is the wrong solution.

As a generic tool, I would say this is correct. It keeps things simple
and straight-forward. Worst case, you see a strange result at the end,
rather than getting an instant exception; in fact, it's very similar
to NaN, in that some operations might cancel out the "error" status.

ChrisA


More information about the Python-ideas mailing list