Closed zaufi closed 3 years ago
see #6
see #6
Oh... %(
To include anchors, a literal including and parsing are needed. But the constructor
would parse the including parts first.
For such a thing, a template engine like Jinja2 may be useful. We shall render all YAML data into a whole one, then parse it.
eg:
bar1.yml:
bar1: *boo
k1: "1.1"
k2: "1.2"
bar2.yml
bar2: *boo
k1: "2.1"
k2: "2.2"
from textwrap import dedent
import jinja2
import yaml
env = jinja2.Environment(loader=jinja2.FileSystemLoader("search path"))
tpl = env.from_string(dedent('''
boo: &boo
k1: "0.1"
k2: "0.2"
bars:
{% include bar1.yml %}
{% include bar2.yml %}
''').strip())
s = tpl.render()
yaml.load(s)
However, above code can NOT work properly, because of indention problem.
I've got the following files:
and
The following code doesn't work: