Next / Previous / Contents / Shipman's homepage

7. class MixedValue: Handling mixed unit systems

The package uses a number of systems of mixed units:

Operations on mixed-unit quantities include:

In order to make calculations on mixed units, it is necessary to define the relative size of the units in the system. For example, in the days-hours-minutes-seconds system, there are 24 hours in a day, 60 minutes in an hour, and 60 hours in a second.

So we'll define a sequence called the factor list as a Python sequence containing these factors. For example, the factor list for the days-hours-minutes-seconds system is (24, 60, 60). The factor list for a mixed unit system with N units always has length (N-1).

7.1. MixedValue.__init__(): Constructor

To create a MixedValue instance:

MixedValue(factorList, coeffList)

A factor list as discussed above. Example: (24, 60, 60) for the days-hours-minutes-seconds system.


A list of coefficients from largest to smallest. If the list is shorter than the length of the factorList plus one, the returned value will assume zero values for the omitted positions. For convenience, you may also provide a single numeric scalar representing the largest units. Here are some examples in the hours-minutes-seconds system, and what they represent.

(1, 2, 3) One hour, two minutes, three seconds.
(1, 2) One hour, two minutes.
[14] Fourteen hours exactly.
14.5 Fourteen hours and thirty minutes.

For example, here is how you would create an instance to represent 10:32:04AM in the hours-minutes-seconds mixed units system.

then = MixedValue((60, 60), (10, 32, 4))