I have a YAML file with an unknown number of "layers", so when I load it to a Python dictionary it becomes a nested dictionary.
I don't want to allow keys without values in the YAML file. I'd like to either:
- cause errors during
yaml.load()if there are missing values, or - identify all
Nonevalues within the resulting nested dictionary.
import yaml
with open(input_path, "r") as yaml_file:
my_dict = yaml.load(yaml_file)
You can redefine the
Parser'sprocess_empty_scalarmethod to raise an error:The above raises an error, if you comment out the assignment to
.process_empty_scalarit parses correct.Please note:
dicts will be formed.loadwhich is documented to be unsafe and almost guaranteed to be inappropriate.