dantro._yaml module¶
Takes care of all YAML-related imports and configuration
-
dantro._yaml.load_yml(path: str, *, mode: str = 'r') → dict[source]¶ Loads a yaml file from a path
- Parameters
path (str) – The path to the yml file
mode (str, optional) – Read mode
- Returns
The parsed dictionary data
- Return type
dict
-
dantro._yaml.write_yml(d: dict, *, path: str, mode: str = 'w')[source]¶ Write a dict as a yaml file to a path
- Parameters
d (dict) – The dict to convert to dump
path (str) – The path to write the yml file to
mode (str, optional) – Write mode of the file
-
dantro._yaml.yaml_dumps(obj: Any, *, register_classes: tuple = (), **dump_params) → str[source]¶ Serializes the given object using a newly created YAML dumper.
The aim of this function is to provide YAML dumping that is not dependent on any package configuration; all parameters can be passed here.
In other words, his function does _not_ use the dantro._yaml.yaml object for dumping but each time creates a new dumper with fixed settings. This reduces the chance of interference from elsewhere. Compared to the time needed for serialization in itself, the extra time needed to create the new ruamel.yaml.YAML object and register the classes is negligible.
- Parameters
obj (Any) – The object to dump
register_classes (tuple, optional) – Additional classes to register
**dump_params – Dumping parameters
- Returns
The output of serialization
- Return type
str
- Raises
ValueError – On failure to serialize the given object