sidpy.base.string_utils.format_size

sidpy.base.string_utils.format_size(size_in_bytes, decimals=2)[source]

Formats the provided size in bytes to kB, MB, GB, TB etc.

Parameters:
  • size_in_bytes (number) – size in bytes

  • decimals (uint, optional. default = 2) – Number of decimal places to which the size needs to be formatted

Returns:

String with size formatted correctly

Return type:

str

Examples

>>> # using the function to print available memory / RAM in system:
>>> import sidpy
>>> mem_in_bytes = sidpy.comp_utils.get_available_memory()
>>> print('Available memory in this machine: {}'
>>>       ''.format(sidpy.string_utils.format_size(mem_in_bytes)))

See also

sidpy.comp_utils.get_available_memory