Unit(number, prefix, unit_type)¶
This class serves for simple comparison of numbers that have units.
Imagine you pull a text value from the UI. 2 GB. By doing
Unit.parse('2 GB')you get an instance of
Unit, which is comparable.
If you compare
Unitonly (or a string that gets subsequently parsed), it also takes the kind of the unit it is, you cannot compare bytes with hertzes. It then calculates the absolute value in the base units and that gets compared.
If you compare with a number, it does it like it was the number of the same unit. So eg. doing:
Unit.parse('2 GB') == 2 *1024 * 1024 * 1024 `` is True
parsing only the numbers in the string