TutorialΒΆ
This tutorial will guide you through the basics of Qty.
Install Qty (see Installation).
Import the relevant classes from the
qty
module. This tutorial uses units of energy.1
>>> from qty import Energy
Instantiate a quantity object.
2
>>> quantity = Energy()
Assign a value to the quantity object using one of the available units. Each unit is implemented as a descriptor that includes a setter and a getter. The setter converts and stores the quantity to the base units of the class. For example, the base units of the
Energy
class are joules (J). The getter converts and returns the quantity in the desired units.3
>>> quantity.meV = 1600.
Note
The units are implemented as descriptors and are therefore assigned and accessed without arguments.
To obtain the quantity in different units, simply access the corresponding attribute.
4 5
>>> quantity.nm 774.9012402075016