from qtty import Quantity, DerivedQuantity, DerivedUnit, Unit, UnitIdUnit is an alias for UnitId.
Construction:
from qtty import Quantity, Unit
q = Quantity(42.0, Unit.Meter)Properties:
q.valueq.unit
Main methods:
q.to(unit)q.to_json()Quantity.from_json(json_str)
Supported operators:
+,-between compatible quantities*and/with scalars/with anotherQuantity- unary
+, unary-,abs(...) - comparisons between compatible quantities
Division behavior:
- compatible dimensions return a
Quantityratio in the left operand unit - different dimensions return a
DerivedQuantity
Construction:
from qtty import DerivedQuantity, Unit
speed = DerivedQuantity(10.0, Unit.Meter, Unit.Second)Properties:
valuenumeratordenominator
Main methods:
symbol()to(numerator, denominator)to_json()DerivedQuantity.from_json(json_str)
Supported operators:
*and/with scalars- unary
-
DerivedUnit is a lightweight helper for a numerator and denominator pair.
from qtty import DerivedUnit, Unit
unit = DerivedUnit(Unit.Kilometer, Unit.Hour)
print(unit.symbol())- incompatible dimensions raise
TypeError - division by zero raises
ZeroDivisionError - unsupported operators raise
TypeErrororNotImplementedError
Pickle works for:
QuantityDerivedQuantityUnitId
JSON helpers are provided on Quantity and DerivedQuantity.