src.pydasa.core.io ================== .. py:module:: src.pydasa.core.io .. autoapi-nested-parse:: Module io.py =========================================== 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: #. Algorithms, 4th Edition, Robert Sedgewick and Kevin Wayne. #. Data Structure and Algorithms in Python, M.T. Goodrich, R. Tamassia, M.H. Goldwasser. Attributes ---------- .. autoapisummary:: src.pydasa.core.io.READ src.pydasa.core.io.WRITE src.pydasa.core.io.PATTERN src.pydasa.core.io.AVAIL_FMT Functions --------- .. autoapisummary:: src.pydasa.core.io.load_json src.pydasa.core.io.save_json src.pydasa.core.io.load src.pydasa.core.io.save Module Contents --------------- .. py:data:: READ :value: 'r' .. py:data:: WRITE :value: 'w' .. py:data:: PATTERN :value: 'utf-8' .. py:data:: AVAIL_FMT :value: ['.json'] .. py:function:: load_json(file_path) *load_json()* reads a JSON file and returns its content as a dictionary. :param file_path: Path to the JSON file. :type file_path: str | Path :returns: Dictionary with the JSON content. :rtype: dict[str, Any] .. py:function:: save_json(data, file_path, indent = 4) *save_json()* writes a dictionary to a JSON file. :param data: Dictionary to be saved. :type data: dict[str, Any] :param file_path: Path to the output JSON file. :type file_path: str | Path :param indent: Indentation level. Defaults to 4. :type indent: int, optional .. py:function:: load(file_path) *load()* generic load function - detects format from file extension. :param file_path: Input file path. :type file_path: str | Path :raises ValueError: If unsupported file format. :returns: Loaded data as a dictionary. :rtype: dict[str, Any] .. py:function:: save(data, file_path, **kwargs) *save()* generic save function - detects format from file extension. :param data: Data to be saved. :type data: dict[str, Any] :param file_path: Output file path. :type file_path: str | Path :param \*\*kwargs: Additional keyword arguments for specific save functions. :raises ValueError: If unsupported file format.