Utils Module#

Functions#

This module provides utility functions for numerical formatting and terminal interaction.

Available Functions#

  • EngNot : Converts numeric values into engineering notation with optional SI prefixes.

  • RevEngNot : Parses strings in engineering notation (e.g., ‘10k’, ‘2.2u’) back to numeric values.

  • printProgressBar : Displays a live progress bar in the terminal during loops or iterative processes.

These tools are designed for convenience in scientific computing, logging, and command-line applications.

chrispytools.utils.EngNot(x, sig_figs=3, si=True, exp=True)#

Format a number in engineering notation using powers of 10 in multiples of 3.

Based on Stack Overflow.

Parameters:
  • x (float or int) – The numeric value to format. If NaN, returns an empty string.

  • sig_figs (int, optional) – Number of significant figures to display (default is 3).

  • si (bool, optional) – If True, use SI unit prefixes instead of exponent notation. E.g., “k” for 10³, “n” for 10⁻⁹. If False, the format uses exponential notation like “e3” (default is True).

  • exp (bool, optional) – Reserved for future use. Currently has no effect on formatting (default is True).

Returns:

A string representation of x in engineering notation, optionally using SI prefixes.

Return type:

str

chrispytools.utils.RevEngNot(x)#

Convert a string formatted with SI unit prefixes into a float.

Parameters:

x (str) – A numeric string with an optional SI unit prefix. Supported prefixes: - Positive: ‘k’, ‘M’, ‘G’, ‘T’, ‘P’, ‘E’, ‘Z’, ‘Y’ - Negative: ‘m’, ‘u’, ‘n’, ‘p’, ‘f’, ‘a’, ‘z’, ‘y’

Returns:

The corresponding numeric value. If the input is invalid or results in NaN, returns an empty string.

Return type:

float

chrispytools.utils.printProgressBar(iteration: int, total: int, prefix: str = 'Progress', suffix: str = 'Complete', decimals: int = 1, length: int = 50, fill: str = '█', print_end: str = '\r') None#

Displays a terminal progress bar.

This function prints a dynamically updating progress bar in the terminal. It is typically used inside a loop to visually track progress.

Parameters:
  • iteration (int) – Current iteration count (e.g., loop index).

  • total (int) – Total number of iterations.

  • prefix (str, optional) – Text displayed before the progress bar.

  • suffix (str, optional) – Text displayed after the progress bar.

  • decimals (int, optional) – Number of decimal places to show in the percentage.

  • length (int, optional) – Total character width of the progress bar.

  • fill (str, optional) – Character used to fill the progress portion of the bar.

  • print_end (str, optional) – End character printed after the bar.

Returns:

Prints directly to stdout.

Return type:

None