Skip to main content

Functions for decomposing nonnegative integers according to various unit scales.

Presupplied scales:

  • BINARY_BYTES_SCALE: Units of (B)ytes, KiB, MiB, GiB etc.
  • DECIMAL_BYTES_SCALE: Units of (B)ytes, KB, MB, GB etc.
  • DECIMAL_SCALE: Unit prefixes K, M, G etc.
  • TIME_SCALE: Units of (s)econds, (m)inutes, (h)ours, (d)ays and (w)eeks.

Function combine(components, scale)

Combine a sequence of value components as from human() into an integer.

Function geek_bytes(n)

Decompose a nonnegative integer n into counts by unit from BINARY_BYTES_SCALE.

Function human(n, scale)

Decompose a nonnegative integer n into counts by unit from scale.

Parameters:

  • n: a nonnegative integer.
  • scale: a sequence of (factor,unit) where factor is the size factor to the follow scale and unit is the designator of the unit.

Function human_bytes(n)

Decompose a nonnegative integer n into counts by unit from DECIMAL_BYTES_SCALE.

Function human_time(n, scale=None)

Decompose a nonnegative integer n into counts by unit from TIME_SCALE.

Function multiparse(s, scales, offset=0)

Parse an integer followed by an optional scale and return computed value. Returns the parsed value and the new offset.

Parameters:

  • s: the string to parse.
  • scales: an iterable of scale arrays of (factor, unit_name).
  • offset: starting position for parse.

Function parse(s, scale, offset=0)

Parse an integer followed by an optional scale and return computed value. Returns the parsed value and the new offset.

Parameters:

  • s: the string to parse.
  • scale: a scale array of (factor, unit_name).
  • offset: starting position for parse.

Function transcribe(n, scale, max_parts=None, skip_zero=False, sep='')

Transcribe a nonnegative integer n against scale.

Parameters:

  • n: a nonnegative integer.
  • scale: a sequence of (factor, unit) where factor is the size factor to the follow scale and unit is the designator of the unit.
  • max_parts: the maximum number of components to transcribe.
  • skip_zero: omit components of value 0.
  • sep: separator between words, default: ''.

Function transcribe_bytes_geek(n, max_parts=1, **kw)

Transcribe a nonnegative integer n against BINARY_BYTES_SCALE.

Function transcribe_bytes_human(n, max_parts=1, **kw)

Transcribe a nonnegative integer n against DECIMAL_BYTES_SCALE.

Function transcribe_time(n, max_parts=3, **kw)

Transcribe a nonnegative integer n against TIME_SCALE.

Release files for cs-units 20181228

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs-units 20181228
File Size Uploaded
cs.units-20181228.tar.gz 3.4 kB Details

Release files / cs.units-20181228.tar.gz

Download URL cs.units-20181228.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4e2c4cf63356e4d2ae6faa65d46afe4ed23564b925afed068aee988d114e3490
BLAKE2b-256 checksum
How to use checksums
812a8ab5be6b4745386144920122901908d9a6404a9561c166460c97475850a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.6

Release history Release notifications | RSS feed

This release

20181228 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page