human_readable_mem#
- detkit.human_readable_mem(m, pad=False)#
Converts memory (in bytes) as float to string with memory unit.
- Parameters:
- padboolean, default=False
If True, adds empty string padding to the left so that the output string always have a consistent and fixed length. This is useful to print the results on a column of fixed length. If False, the padding on the left of the string is removed.
- Returns:
- stringstr
A string containing the memory and its unit. The unit can be
'B'
: Byte'KB'
: Kilo-Byte (\(2^{10}\) bytes)'MB'
: Mega-Byte'GB'
: Gga-Byte'TB'
: Tiga-Byte'TB'
: Tera-Byte'PB'
: Peta-Byte'EB'
: Exa-Byte
See also
Examples
>>> from detkit import human_readable_mem >>> print(human_readable_mem(2048)) 2 KB >>> print(human_readable_mem(2048, pad=True)) 2 KB