What does HackerNews think of pint?

Operate and manipulate physical quantities in Python

Language: Python

#124 in Python
Only tangential to this but somebody might find it usefull. I’m doing lots of calculations in Python involving various units. I’m using a similar library called Pint. https://github.com/hgrecco/pint

My business is thermodynamics of power plants. Professionals in the industry tend to use convenient units like C, bars, kJ/kg and so on. But the formulas usualy need basic SI units. Using this library not only streamlines the conversion process but also keeps track of the unit itself. So instead of variable turbine_output_gj and turbine_output_mw I can have just turbine_output which is convenient.

It is hard to put a value on that but I believe it has already spared me many trivial mistakes that I had to explain to my clients.

In Python, [JupyterLite or Mamba] Pint and Uncertainties might be helpful for units and uncertainty/error propagation.

The https://numpy.org/ pyolite (WASM) IPython demo has SymPy installed in the env but not Pint?

[1] https://github.com/hgrecco/pint

[2] https://github.com/lebigot/uncertainties

Reason for submission: learned about the existence of this library after discovering the Astropy Units module[1] thanks to this HN comment[2] which notes some similarity between it and pint[3].

[1] - https://docs.astropy.org/en/stable/units/index.html

[2] - https://news.ycombinator.com/item?id=28415151

[3] - https://github.com/hgrecco/pint

Great application and writeup, thanks for sharing (and making it open source)!

The file-based approach to defining data is a good way to go I reckon - it's simple and easy to update (especially with source control). You can always upgrade to something more sophisticated in future.

How complete/challenging does the unit conversion component feel, out of interest? (I'm reading through `conversion.ts` in the codebase at the moment)

By chance I'm working on some ingredient unit conversion code too - I'd be happy to learn from & share experiences. FWIW the tools I'm exploring are Pint[0] and convert-units[1].

[0] - https://github.com/hgrecco/pint

[1] - https://github.com/ben-ng/convert-units

I use Python with pint [0] for this. It integrates with numpy. It has support for uncertainty. You can do all calculations Python can, Python math reads like ascii math. It also can output to latex.

This can easily run local. If you prefer online repl, it's available on repl.it [1]. There you can keep your scripts in the cloud for later, with rudimentary versioning.

[0] https://github.com/hgrecco/pint [1] https://repl.it