On Tue, Apr 12, 2022 at 11:27 AM Christopher Barker <pythonchb@gmail.com> wrote:
 > > 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)

I will try to finish my email about this I started writing a week ago!

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler