[Python-ideas] SI scale factors in Python
Ivan Levkivskyi
levkivskyi at gmail.com
Fri Aug 26 07:52:07 EDT 2016
On 26 August 2016 at 14:49, Ivan Levkivskyi <levkivskyi at gmail.com> wrote:
> On 26 August 2016 at 13:01, Steven D'Aprano <steve at pearwood.info> wrote:
>
>> On Fri, Aug 26, 2016 at 07:35:36AM +0200, Pavol Lisy wrote:
>> > On 8/25/16, Ken Kundert <python-ideas at shalmirane.com> wrote:
>> >
>> > [...]
>> >
>> > > Just allowing the units to be present, even it not
>> > >
>> > > retained, is a big advantage because it can bring a great deal of
>> clarity to
>> > > the
>> > > meaning of the number. For example, even if the language does not
>> flag an
>> > > error
>> > > when a user writes:
>> > >
>> > > vdiff = 1mV - 30uA
>> >
>> > It reminds me: "Metric mishap caused loss of NASA's Mars Climate
>> > orbiter. It could be nice to have language support helping to avoid
>> > something similar.
>>
>
> [snip]
>
>
>> Take v = s/t (velocity equals distance over time). If I write v = s
>> because it is implicitly understood that the time t is "one":
>>
>> s = 100 miles
>> v = s
>>
>> Should v be understood as 100 miles per hour or 100 miles per second or
>> 100 miles per year? That sort of ambiguity doesn't come up in circuit
>> design, but it is common elsewhere.
>>
>
> If one writes this as
>
> from units import m, s, miles
>
> s = miles(100)
> v: m/s = s
>
Sorry for a name collision in this example. It should read:
dist = miles(100)
vel: m/s = dist
--
Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160826/0fc17d71/attachment.html>
More information about the Python-ideas
mailing list