Skip to content
Snippets Groups Projects
Commit 7f03f93c authored by JuanPi Carbajal's avatar JuanPi Carbajal
Browse files

feat: utils module

parent 5110ab92
Branches
No related tags found
No related merge requests found
from pathlib import Path
from typing import Union
import yaml
def yaml_load(file_path: Union[str, Path], *, ignore_private: bool = True) -> dict:
"""Load YAMl file, ignoring private fields (prefix: "__").
Parameters
----------
file_path:
Path to YAML file.
ignore_private:
Flag to disable loading of private fields in the YAML file.
Returns
-------
data:
A dict containing the loaded key-value pairs from the YAML file.
"""
with open(file_path, encoding="utf8") as file:
# The FullLoader parameter handles the conversion from YAML
# scalar values to Python the dictionary format
data = yaml.load(file, Loader=yaml.FullLoader)
if ignore_private:
# erase private fields (starts with __)
for k in tuple(k_ for k_ in data.keys() if str(k_).startswith("__")):
data.pop(k)
return data
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment