Variable Substitution in YAML not performed before loading into Python

Viewed 21
vars:
  version: 0.0.1
  path:
    train: ./data/for-training-cnn
    test: ./data/for-testing-cnn
    model: "./data/model/sandbox"
test: ${vars.path.model}

YML file

import yaml
from yaml import Loader

config = yaml.load(open("this.yml"), Loader=Loader)
print(config['test']) # Output -> "${vars.path.model}" not "./data/model/sandbox"

PY file

Shouldn't config['test'] contain ./data/model/sandbox, not ${vars.path.model}. Why isn't the variable being substituted?

I used YAMLLint to verify that my syntax is correct. Printing out config yeilds the expected nested dictionary, but the variable still isn't substituted with its value.

I understand that YAML, like JSON, is a data format that does no processing. But, then how does this work? Their code doesn't seem to do any processing of the YAML file, but perhaps I missed it.

0 Answers
Related