Posts

Showing posts from May, 2013

A Pint a day ...

A few months ago I wrote about Pint , a Python units library that we developed for Lantz . With Pint  you can define physical quantities: the product of a numerical value and a unit of measurement. Pint can convert between units and perform mathematical operation between quantities. For example: >>> from pint import UnitRegistry >>> ureg = UnitRegistry() >>> my_beer = ureg.pint >>> print(my_beer.to('liter')) 0.473176473 liter >>> print(my_beer.dimensionality) [length] ** 3 >>> ureg.pint < ureg.imperial_pint True >>> ureg.pint < ureg.liter True As described in the Design principles section of the documentation, units definitions are loaded from a text file which is simple and easy to edit. Adding and changing units and their definitions does not involve changing the code. Prefixed and pluralized forms of units are recognized without explicitly defining them. In other words: as the prefix kilo and the u