src.pydasa.core.io#

Generic I/O operations for PyDASA.

This module provides functions for reading and writing data to files, handling different data formats (JSON, CSV, etc.), and ensuring compatibility with the data structures used in PyDASA.

IMPORTANT: based on the implementations proposed by the following authors/books:

  1. Algorithms, 4th Edition, Robert Sedgewick and Kevin Wayne.

  2. Data Structure and Algorithms in Python, M.T. Goodrich, R. Tamassia, M.H. Goldwasser.

Attributes#

Functions#

load_json(file_path)

load_json() reads a JSON file and returns its content as a dictionary.

save_json(data, file_path[, indent])

save_json() writes a dictionary to a JSON file.

load(file_path)

load() generic load function - detects format from file extension.

save(data, file_path, **kwargs)

save() generic save function - detects format from file extension.

Module Contents#

src.pydasa.core.io.READ = 'r'#
src.pydasa.core.io.WRITE = 'w'#
src.pydasa.core.io.PATTERN = 'utf-8'#
src.pydasa.core.io.AVAIL_FMT = ['.json']#
src.pydasa.core.io.load_json(file_path)#

load_json() reads a JSON file and returns its content as a dictionary.

Parameters:

file_path (str | Path) – Path to the JSON file.

Returns:

Dictionary with the JSON content.

Return type:

dict[str, Any]

src.pydasa.core.io.save_json(data, file_path, indent=4)#

save_json() writes a dictionary to a JSON file.

Parameters:
  • data (dict[str, Any]) – Dictionary to be saved.

  • file_path (str | Path) – Path to the output JSON file.

  • indent (int, optional) – Indentation level. Defaults to 4.

Return type:

None

src.pydasa.core.io.load(file_path)#

load() generic load function - detects format from file extension.

Parameters:

file_path (str | Path) – Input file path.

Raises:

ValueError – If unsupported file format.

Returns:

Loaded data as a dictionary.

Return type:

dict[str, Any]

src.pydasa.core.io.save(data, file_path, **kwargs)#

save() generic save function - detects format from file extension.

Parameters:
  • data (dict[str, Any]) – Data to be saved.

  • file_path (str | Path) – Output file path.

  • **kwargs – Additional keyword arguments for specific save functions.

Raises:

ValueError – If unsupported file format.

Return type:

None