Documentation

Below is documentation for the various features in this module!

Quantity

This is the class that will manage most of your conversions. To import this, you can run either of the following:

from unisci import Quantity
from unisci.types import Quantity

You can create a Quantity using a constructor in the following format:

Quantity(<value>, <dict>)

Where <value> is the numerical value of the Quantity and <dict> is a dictionary of units and their powers. For example, here is the initialization of a Quantity holding the value 1.0 m/s².

length = Quantity(1, {'m': 1, 's': -2})
print(length)
1.000*10⁰ m/s²

Below are methods associated with this class. x represents an arbitrary Quantity object.

Quantity.set_precision()

Quantity.set_precision(number: int) -> None

Sets the precision (number of decimal places) of printing output. The default value is 3, which is why the above example prints 1.000 rather than 1.0. The below example sets the precision to 2 decimal places.

Quantity.set_precision(number=2)

Quantity.set_auto_format()

Quantity.set_auto_format(do: bool) -> None

Determines if the auto-conversions should be done. For example, when multiplying Quantity’s with units m and in, if auto_format is enabled, the product will be in the units of the first number. It also enables auto-condensation of complicated units, which will be elaborated upon further regarding the x.simplified() method.