mltk.utils.string_formatting

String formatting utilities

See the source code on Github: mltk/utils/string_formatting.py

Functions

convert_units(v)

Convert human-readable string representing memory size to integer corresponding to memory size in bytes

format_units(value[, precision, add_space, ...])

Convert the given numeric value to a string with units

iso_time_filename_str()

Return the current time as ISO 8601 format that is suitable for a filename e.g.: 2019-01-19T23-20-25-459

iso_time_str()

Return the current time as ISO 8601 format e.g.: 2019-01-19T23:20:25.459Z

pretty_time_str()

Return the current time as Y-m-d H-M-S

class FormattedInt[source]
__str__()[source]

Return str(self).

__dict__ = mappingproxy({'__module__': 'mltk.utils.string_formatting', '__str__': <function FormattedInt.__str__>, '__dict__': <attribute '__dict__' of 'FormattedInt' objects>, '__doc__': None, '__annotations__': {}})
__module__ = 'mltk.utils.string_formatting'
class FormattedFloat[source]
__str__()[source]

Return str(self).

__dict__ = mappingproxy({'__module__': 'mltk.utils.string_formatting', '__str__': <function FormattedFloat.__str__>, '__dict__': <attribute '__dict__' of 'FormattedFloat' objects>, '__weakref__': <attribute '__weakref__' of 'FormattedFloat' objects>, '__doc__': None, '__annotations__': {}})
__module__ = 'mltk.utils.string_formatting'
__weakref__

list of weak references to the object

format_units(value, precision=3, add_space=True, ljust=0, rjust=0, memory_units=False)[source]

Convert the given numeric value to a string with units

Example: 0.0314 -> 31.4m

Return type:

str

Parameters:
  • value (Union[int, float]) –

  • precision (int) –

  • add_space (bool) –

  • ljust (int) –

  • rjust (int) –

  • memory_units (bool) –

convert_units(v)[source]

Convert human-readable string representing memory size to integer corresponding to memory size in bytes

e.g.:

‘32kb’ -> 32768 ‘2*128M’ -> 268435456

Return type:

int

Parameters:

v (str) –

pretty_time_str()[source]

Return the current time as Y-m-d H-M-S

Return type:

str

iso_time_str()[source]

Return the current time as ISO 8601 format e.g.: 2019-01-19T23:20:25.459Z

Return type:

str

iso_time_filename_str()[source]

Return the current time as ISO 8601 format that is suitable for a filename e.g.: 2019-01-19T23-20-25-459

Return type:

str