Easily use and manipulate unit-aware measurements in Python
Easily use and manipulate unit-aware measurement objects in Python.
django.contrib.gis.measure has these wonderful ‘Distance’ objects that can be used not only for storing a unit-aware distance measurement, but also for converting between different units and adding/subtracting these objects from one another.
This module not only provides those Distance and Area measurement objects, but also other measurements including:
>>> from measurement.measures import Weight >>> weight_1 = Weight(lb=125) >>> weight_2 = Weight(kg=40) >>> added_together = weight_1 + weight_2 >>> added_together Weight(lb=213.184976807) >>> added_together.kg # Maybe I actually need this value in kg? 96.699
Measurements are stored internally by converting them to a floating-point number of a (generally) reasonable SI unit. Given that floating-point numbers are very slightly lossy, you should be aware of any inaccuracies that this might cause.
TLDR: Do not use this in navigation algorithms guiding probes into the atmosphere of extraterrestrial worlds.
- Documentation for python-measurement is available an ReadTheDocs.
- Please post issues on Github.
- Test status available on Travis-CI.