Question: Syntax of multiple dictionaries in one YAML file and how to access each one of them with PyYAML
I have a few small dictionaries which I would like to include in one yaml file and access each one of them separately with PyYAML. After having some trouble finding out how to write the YAML file, I ended up with this version, where
--- is supposed to distinguish the two dictionaries, which are named as elements and as parameters. This was inspired by this post and answer
--- !elements n: 'N' p: 'P' k: 'K' --- !parameters ph: 'pH' org_mat : 'organic matter'
To continue, I created a variable with the name of the path of the file:
yaml_fpath = r"\Users\user1\Desktop\yaml_file" and I tried several methods to access the dictionaries, such as:
for item in yaml.safe_load_all(yaml_fpath): print(item)
yaml.safe_load(open(yaml_fpath, 'r', encoding = 'utf-8'))
but none does what I need. In fact, I would like to load the file and be able to call each dictionary python error by each name when I need to use it.
What am I missing from the documentation of PyYAML?