shared.io¶
Input/output operations for JSON configuration files.
Attributes¶
Classes¶
Input/output class for JSON operations. |
Module Contents¶
- class IO(file_path: str | pathlib.Path)¶
Input/output class for JSON operations.
- static file_exists(file_path: str | pathlib.Path) → bool¶
Check if the file exists.
- Args:
file_path: Path to the file to check.
- Returns:
bool: True if the file exists, False otherwise.
- static folder_check(checkpath: str | pathlib.Path) → pathlib.Path¶
Check if the folder exists and create if it doesn’t.
- Args:
checkpath: File or folder path to check.
- Returns:
Path: Passes checkpath input back as Path.
- read(file_path: str | pathlib.Path | None = None) → dict | list | str | int | float | bool¶
Read data from file.
- Args:
- file_path: If defined, data will be read from this file
instead of the class variable. Defaults to None.
- Returns:
- dict | list | str | int | float | bool: Contents of the file
if it exists. Returns False if the file does not exist.
- set_file_path(new_path: str | pathlib.Path) → None¶
Set the file path.
- Args:
new_path: File path to be set.
- Raises:
Exception: If the extension is not defined. Exception: If the extension is not among valid extensions.
- write(data: Any, file_path: str | pathlib.Path | None = None) → pathlib.Path¶
Write data to the given or class-defined file_path.
- Args:
data: Data to write. file_path: If defined, the data is written into the specified path
rather than the class defined. Defaults to None.
- Returns:
Path: Path to the file.
- Raises:
Exception: If file path is not set.
- file_path: pathlib.Path | None = None¶
- valid_extensions = ['.json']¶
- LOG¶