Skip to content

yaml anchors and aliases #787

Answered by Jasha10
LDderlee asked this question in Q&A
Sep 7, 2021 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @Lads0909,
Does the following work for you?

# file_containing_data.yml
master_data:
  data1: data_value
# extension_file1.yml
slave_data_1:
  master_data: ${master_data.data1}
# extension_file2.yml
slave_data_2:
  master_data: ${master_data.data1}
# main.py
from omegaconf import OmegaConf

cfg1 = OmegaConf.load("file_containing_data.yml")
cfg2 = OmegaConf.load("extension_file1.yml")
cfg3 = OmegaConf.load("extension_file2.yml")

cfg_merged = OmegaConf.merge(cfg1, cfg2, cfg3)
OmegaConf.resolve(cfg_merged)

assert cfg_merged == {
    "master_data": {"data1": "data_value"},
    "slave_data_1": {"master_data": "data_value"},
    "slave_data_2": {"master_data": "data_value"},
}

Also, I'd rec…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@LDderlee
Comment options

Answer selected by LDderlee
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants