Input/Output (IO)

IO Utils

class CommonIOUtils

Bases: object

Utilities for reading/writing to and from files.

static load_from_file(file_path, buffering=1, encoding='utf-8')

Load string data from a file.

Parameters:
  • file_path (str) – The file to read from.
  • buffering (int, optional) – See the built-in python open() function documentation for more details.
  • encoding (str, optional) – See the built-in python open() function documentation for more details.
Returns:

The contents of the file as a string or None if an error occurred.

Return type:

Union[str, None]

static write_to_file(file_path, data, buffering=1, encoding='utf-8', ignore_errors=False)

Write string data to a file.

Parameters:
  • file_path (str) – The file to write to.
  • data (str) – The data to write.
  • buffering (int, optional) – See the built-in python open() function documentation for more details.
  • encoding (str, optional) – See the built-in python open() function documentation for more details.
  • ignore_errors (bool, optional) – If True, any exceptions thrown will be ignored (Useful in preventing infinite loops)
Returns:

True if successful. False if not.

Return type:

bool

JSON IO Utils

class CommonJSONIOUtils

Bases: object

Utilities for reading/writing JSON data to and from files.

static load_from_file(file_path, buffering=1, encoding='utf-8')

Deserialize an object from a JSON file.

Parameters:
  • file_path – The file to read from.
  • buffering (int, optional) – See the built-in python open() function documentation for more details.
  • encoding (str, optional) – See the built-in python open() function documentation for more details.
Type:

file_path: str

Returns:

The contents of the file as an object or None if an error occurred.

Return type:

Union[Any, None]

static write_to_file(file_path, obj, buffering=1, encoding='utf-8')

Serialize an object to a file as JSON.

Parameters:
  • file_path (str) – The file to write to.
  • obj (Any) – The object to write as JSON.
  • buffering (int, optional) – See the built-in python open() function documentation for more details.
  • encoding (str, optional) – See the built-in python open() function documentation for more details.
Returns:

True if successful. False if not.

Return type:

bool