stouputils.io package#
This module provides utilities for file management.
json_dump(): Writes the provided data to a JSON file with a specified indentation depth.json_load(): Load a JSON file from the given pathcsv_dump(): Writes data to a CSV file with customizable optionscsv_load(): Load a CSV file from the given pathget_root_path(): Get the absolute path of the directoryrelative_path(): Get the relative path of a file relative to a given directorysuper_copy(): Copy a file (or a folder) from the source to the destination (always create the directory)super_open(): Open a file with the given mode, creating the directory if it doesn’t exist (only if writing)replace_tilde(): Replace the “~” by the user’s home directoryclean_path(): Clean the path by replacing backslashes with forward slashes and simplifying the pathcopytree_with_progress(): Copy a directory tree with a colored progress barredirect_folder(): Move a folder and create a junction/symlink at the original locationsafe_close(): Safely close a file descriptor or file object after flushing, ignoring any exceptions
import stouputils as stp
config = {"model": "resnet50", "layers": [64, 128, 256], "optimizer": {"name": "adam", "lr": 0.001}}
# Write the dictionary to a JSON file, creating the configs folder on the way
stp.json_dump(config, "configs/run.json")
stp.info("Content of configs/run.json:")
print(stp.read_file("configs/run.json"))
# Read it back
stp.info("Same data back:", stp.json_load("configs/run.json") == config)
# Copy it, creating the destination folders on the way
stp.info("Copied to", stp.super_copy("configs/run.json", "archive/2026/run.json"))
# Simplify a path
stp.info("Cleaned:", stp.clean_path("archive/2026/../2026/./run.json"))