Using the ‘units module for performing basic conversions between units.
However it does not seem to be possible to perform an easy conversion between liters and milliliters…why?
>>> from units import unit
>>> one_liter = unit('L')(1)
>>> one_liter
Quantity(1, LeafUnit('L', False))
>>> unit('mL')(one_liter)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/heinz/src/units/lib/python2.6/site-packages/units/abstract.py", line 23, in __call__
raise IncompatibleUnitsError()
units.exception.IncompatibleUnitsError
You need to call
define_units()in thepredefinedsub-module to use this package.I think this package could have been better designed — as you’ve discovered, it’s easy to accidentally use user-defined units rather than standard ones.