Last active
August 13, 2024 15:00
-
-
Save perlpunk/be76e623963a83a905a3072eb4579ec1 to your computer and use it in GitHub Desktop.
pyyaml-include
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a: 1 | |
b: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
def include_constructor(loader, node): | |
"""Include content at node.""" | |
v = open(node.value).read() | |
return yaml.load(v, Loader=loader.__class__) | |
yaml.add_constructor("!include", include_constructor, Loader=yaml.SafeLoader) | |
string = """ | |
x: &x !include "abc.yaml" | |
y: *x | |
""" | |
data = yaml.safe_load(string) | |
print(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{'x': {'a': 1, 'b': 2}, 'y': {'a': 1, 'b': 2}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment