ExperimentSession.read_yaml_todict()#

ExperimentSession.read_yaml_todict(path: Union[str, pathlib.Path], encoding: str = 'utf-8')[source]#

Imports a .yaml file to a dict.

This method uses the library PyYAML, specifically the function safe_load. See the documentation of PyYAML at https://pyyaml.org/wiki/PyYAMLDocumentation for further information.

Parameters
  • path – The path to the .yaml file. Usually, you want this to be a relative path to a file in a subdirectory of the experiment directory.

  • encoding – Encoding of the .yaml file. Defaults to ‘utf-8’.

Returns

A dict representing the parsed yaml file.

Return type

dict

Examples

This example assumes that you have a .yaml file saved in your experiment directory in the subdirectory resources:

import alfred3 as al

exp = al.Experiment()

@exp.member
class Test(al.Page):
    def on_exp_access(self):
        yaml_dict = self.exp.read_yaml_todict("resources/test_yaml.yaml")
        self += al.Text(str(yaml_dict))