eoio.utils.formatters module#

eoio.utils.formatters - formatting functions for values

eoio.utils.formatters.is_datetime(s)[source]#

Return whether a string is a datetime

Parameters:

s – input string

Returns:

True when the string can be parsed as a datetime, otherwise False.

eoio.utils.formatters.is_number(s)[source]#

Return whether a string is a number

Parameters:

s – input str

Returns:

True when the string can be parsed as a number, otherwise False.

eoio.utils.formatters.list_to_dict(test_list, key=None) dict[source]#

Convert a list of tuples into a dictionary, based on ‘GROUP’ and ‘END_GROUP’ values

Parameters:
  • test_list – list of tuples containing (key, value), (“GROUP”, key) and (“END_GROUP”, key) tuples

  • key – key of the dictionary into which subsequent key-value pairs are added

Returns:

Dictionary containing the parsed key-value pairs.

eoio.utils.formatters.str2datetime(s)[source]#

Convert strings of recognised datetime formats (valid ISO 8601 formats accepted by datetime.datetime.fromisoformat() and datetime.time.fromisoformat()) to datetime objects.

Valid date strings given by: datetime.datetime.fromisoformat() - https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat datetime.time.isoformat() - https://docs.python.org/3/library/datetime.html#datetime.time.fromisoformat

Parameters:

s – input string

Returns:

Datetime object, time object, or the original string value.

eoio.utils.formatters.txt_to_dict(txt_filepath)[source]#

Read in text file into a dictionary

Parameters:

txt_filepath – text file filepath from which to read

Returns:

Dictionary parsed from the text file.

eoio.utils.formatters.val_format(s)[source]#

Change recognised formats of input strings into different types

Parameters:

s – input value

Returns:

Newly formatted value or the original input value.