CONTENTS
------------------------------------------------------
This module has two parts. Part 1 includes:
-
-- head_and_tail: shows the first few and last few elements of an iterable that
- could potentially be pretty long
-- size_str: textual representation of data size
+ - head_and_tail: shows the first few and last few elements of an iterable that
+ could potentially be pretty long
+ - size_str: textual representation of data size
Part2 contains functions for coloring text, a poor-man's version of other
modules like :py:mod:`colorclass` (which is now also available on Intra2net
------------------------------------------------------
"""
-try:
- from builtins import print as _builtin_print
-except ImportError: # different name in py2
- from __builtin__ import print as _builtin_print
+from builtins import print as _builtin_print
from functools import partial
from itertools import islice
Rounds and shortens size to something easily human-readable like '1.5 GB'.
- :param int byte_number: Number of bytes to express as text
+ :param float byte_number: Number of bytes to express as text
:param bool is_diff: Set to True to include a '+' or '-' in output;
default: False
:returns: textual representation of data
# have an impossible amount of data. (>1024**4 GB)
# undo last "/factor" and show thousand-separator
- return '{2}{0:,d} {1}B'.format(int(round(curr_num*factor)), units[-1],
- sign_str)
+ return f'{sign_str}{int(round(curr_num*factor)):,d} {units[-1]}B'
###############################################################################
STYLE_REVERSE = 7
-_COLOR_TO_CODE = dict(zip([COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, \
+_COLOR_TO_CODE = dict(zip([COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW,
COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE],
range(8)))
def colored(text, foreground=None, background=None, style=None):
- """ return text with given foreground/background ANSI color escape seqence
+ """ return text with given foreground/background ANSI color escape sequence
:param str text: text to color
:param str style: one of the style constants above
:param str foreground: one of the color constants to use for text color
or None to leave as-is
- :param str foreground: one of the color constants to use for background
+ :param str background: one of the color constants to use for background
or None to leave as-is
:param style: single STYLE constant or iterable of those
or None to leave as-is