Unum

Units in Python
Download

Unum Ranking & Summary

Advertisement

  • Rating:
  • License:
  • LGPL
  • Price:
  • FREE
  • Publisher Name:
  • Chris MacLeod and Pierre Denis
  • Publisher web site:
  • http://bitbucket.org/kiv/

Unum Tags


Unum Description

Units in Python Unum stands for 'unit-numbers'. It is a Python library that allows you to define and manipulate quantities with units attached such as 60 seconds, 500 watts, 42 miles-per-hour, 100 kg per square meter, 14400 bits per second, 30 dollars, and so on.Features include: - Exceptions for incorrect use of units. - Automatic and manual conversion between compatible units. - Easily extended to arbitrary units. - Integration with any type supporting arithmetic operations, including Numpy arrays and standard library types like complex and fractions.Fraction. - Customizable output formatting.Example:For a simple example, let's can calculate Usain Bolt's average speed during his record-breaking performance in the 2008 Summer Olympics:>>> from unum.units import * # Load a number of common units.>>> distance = 100*m>>> time = 9.683*s>>> speed = distance / time>>> speed10.3273778788 >>> speed.asUnit(mile/h)23.1017437978 If we do something dimensionally incorrect, we get an exception rather than silently computing a correct result. Let's try calculating his kinetic energy using an erroneous formula:>>> KE = 86*kg * speed / 2 # Should be speed squared!>>> KE.asUnit(J)Traceback (most recent call last): File "< stdin >", line 1, in < module > File "unum\__init__.py", line 171, in asUnit s, o = self.matchUnits(other) File "unum\__init__.py", line 258, in matchUnits raise IncompatibleUnitsError(self, other)unum.IncompatibleUnitsError: can't be used with The exception pinpoints the problem, allowing us to examine the units and fix the formula:>>> KE = 86*kg * speed**2 / 2>>> KE.asUnit(J)4586.15355558 Requirements: · Python


Unum Related Software