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
None
values 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_scalar
method to raise an error:The above raises an error, if you comment out the assignment to
.process_empty_scalar
it parses correct.Please note:
dict
s will be formed.load
which is documented to be unsafe and almost guaranteed to be inappropriate.