modunits module

Convert computer-friendly numbers to human-readable numbers with units at various levels of detail.

class modunits.Item(amount: float, type_: Type, after: bool, units: str, fractional_part_length: int)[source]

Bases: object

Hold one of the modular pieces of our number.

class modunits.Options[source]

Bases: object

Hold, parse and verify command line options.

check_options() None[source]

Verify that the options specified make sense.

parse_argv(argv: List[str]) None[source]

Dissect our argv into something useful.

class modunits.Type(threshold: int | None, unabbreviated: str, abbreviated: str)[source]

Bases: object

Hold data about whether we should output units abbreviated or unabbreviated, and what to divide by (?).

modunits.builtins() List[str][source]

Legal options for builtin varieties of modular units.

modunits.detail_options() List[str][source]

Legal options for what level of detail we want.

modunits.main() None[source]

Convert to human-readable form of units.

modunits.modunits(unitsvector: str | List[Type], number: int, detail: str = 'highest-and-fraction', units: str = 'abbreviated', comma: bool = True, reverse: bool = False, after: bool = True, fractional_part_length: int = -1)[source]

Convert a number with computer-friendly units into something more human-readable.

Main entry point for the module.

detail can be:

list (implies that we will ignore units and comma) highest (implies that we will ignore comma) two-highest highest-and-fraction (default) all

units can be:

unabbreviated abbreviated (default)

comma can be:

0 (default) 1

reverse can be:

0 (default) 1

after can be:

0 (default) 1

time expects seconds computer-size-iec expects bytes (http://en.wikipedia.org/wiki/Zettabyte) computer-size and computer-size-si are the same thing. They expect bytes (see wikipedia URL above) computer-bit-seconds and computer-bits-per-second-iec are the same thing. They both expect bits/second computer-bits-per-second-si expects bits/second computer-byte-hours and computer-bytes-per-hour-iec are the same thing. They both expect bytes/hour computer-bytes-per-hour-si expects bytes/hour

modunits.units_type() List[str][source]

Legal options for abbreviation or not.

modunits.usage(retval: int) None[source]

Give usage message to user.