Using pointers to merge elements in yaml file
Yaml example:
pasta:
- pomodoro
- sugo
hamburgher:
- spicy
- onion
I want a new element called ingredients to be the merge of the elements of pasta and hamburgher.
Here's the magic:
pasta: &one
- pomodoro
- sugo
hamburgher: &two
- spicy
- onion
ingredients:
<< : [*one, *two]
This link helped me:
http://stackoverflow.com/questions/9254178/is-there-yaml-syntax-for-sharing-part-of-a-list-or-map
Written by pleone
Related protips
1 Response
It doesn't work in PyYaml:
ConstructorError: while constructing a mapping
in "<string>", line 9, column 3:
<< : [*one, *two]
^
expected a mapping for merging, but found sequence
in "<string>", line 2, column 8:
pasta: &one
^
Even the specs (http://yaml.org/type/merge.html) say that it works only for mappings. I have no idea why it doesn't apply to sequences, it would be very useful indeed
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Symfony
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#