>
>  > > I guess you could call the associative law of multiplication "dumb
>  > > luck", but most mathematicians will consider that hate speech.
>  >
>  > My apologies for not understanding your example.  The counter
>  > example I had in my head, and should have written down,
>  > was something like:
>  >
>  >    15mpg * 7l == how many miles?
>

Using pint:

In [76]: U = pint.UnitRegistry()

In [77]: (15 * U.miles / U.gallons * 7 * U.liter).to('miles')
Out[77]: 27.7380654976056 <Unit('mile')>

A bit verbose, perhaps, but to me clear, and the operator precedence rules
seem to "just work".

And it you want it a tad less verbose, you can give some of those units
names:

In [78]: mpg = U.miles / U.gallons
In [79]: l = U.liter

In [80]: (15 * mpg * 7 * l).to('miles')
Out[80]: 27.7380654976056 <Unit('mile')>

My question for the folks that want units built in to Python is "what's so
hard about that?

Ricky wrote:

"Python is so painful to use for units I've actually avoided it,"

Really? have you tried pint? or anything else? what is so painful about
this?

-CHB

-- 
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/4UB6TGEPEKJTXPPXZ7ZH2OHTWJWMEZ3X/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to