wqgm7g
Last Updated: February 25, 2016
·
10.46K
· pleone
Bug

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

Say Thanks
Respond

1 Response
Add your response

11045
Bf141997fe2868ce9182f3d82c5530d0

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 ·