This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Unit Converter

The unit converter is a simple utility to convert units. While it may seem to be a trivial task initially, there are many different conventions and combinations. Instead of inventing yet another unit conversion utility, this package reuses the units shell command, which has the best implementation that I have found out there.

>>> from keas.unit import unit

The first step is to instantiate the unit converter object:

>>> converter = unit.UnitConverter()

By default the converter uses the following path for the units command:

>>> converter.executable

So let’s make a simple unit conversion:

>>> converter.convert('atm', 'kPa')

There are several options that can be set on the conversion object. The first one is the output format, which allows you to specify the precision on the output. Of course, we then convert this output to a decimal:

>>> converter.format
>>> converter.format = '%.15g' # 15 decimal places
>>> converter.convert('atm', 'kPa')

Next you can specify additional unit conversion data filenames, so that custom conversions can be loaded:

>>> import os
>>> datafile = os.path.join(
...     os.path.dirname(unit.__file__), 'test-conversions.dat')
>>> converter.filenames
>>> converter.filenames = ('', datafile)
>>> converter.convert('keas', 'l')
>>> converter.filenames = None

An empty name means that the default data file should be loaded as well.

The final option allows you to set whether the ‘-‘ character should be treated as a multiplication operator, since it is used as such in some notations.

>>> converter.minusAsProduct
>>> converter.minusAsProduct = True
>>> converter.convert('m-m-m', 'l')

Finally, let’s have a look at some error scenarios.

  1. There is no known conversion from one unit to another:
>>> converter.convert('kg', 'm')
Traceback (most recent call last):
UnitConversionError: ('/usr/bin/units -t -o %.15g -p "kg" "m"',
                      'conformability error')
  1. One of the units is unknown:
>>> converter.convert('kg', 'foo')
Traceback (most recent call last):
UnitConversionError: ('/usr/bin/units -t -o %.15g -p "kg" "foo"',
                      "Unknown unit 'foo'")
  1. One of the units contains an invalid expression:
>>> converter.convert('kg', 'm *')
Traceback (most recent call last):
UnitConversionError: ('/usr/bin/units -t -o %.15g -p "kg" "m *"',
                      "Error in 'm *': Parse error")


1.0.0 (2009-07-26)

  • Initial release.
Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
keas.unit-1.0.0.tar.gz (5.3 kB) Copy SHA256 Checksum SHA256 Source Jul 27, 2009

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting