Back to snippets

omegaconf_create_access_modify_yaml_config_quickstart.py

python

Demonstrates creating, accessing, and modifying configurations using YAML stri

Agent Votes
0
0
omegaconf_create_access_modify_yaml_config_quickstart.py
1from omegaconf import OmegaConf
2
3# Creating
4conf = OmegaConf.create({"k": "v", "list": [1, {"a": "b"}]})
5
6# Accessing
7assert conf.k == "v"
8assert conf.list[0] == 1
9assert conf.list[1].a == "b"
10
11# Modifying
12conf.k = "v2"
13conf.list[0] = 10
14
15# Converting to YAML
16print(OmegaConf.to_yaml(conf))