Yaml dump for python lists uses inline format instead of hypen + space

Viewed 6005

I have a python ordered dictionary like,

from collections import OrderedDict 
a = OrderedDict()
a['name'] = 'hello'
a['msgs'] = ['hello', 'world']

And I am converting it to YAML syntax as,

import yaml
with open("b.yaml", 'w') as stream:
  stream.write(yaml.dump(a))

It prints,

!!python/object/apply:collections.OrderedDict
- - [name, hello]
  - - msgs
    - [hello, world]

Whereas, I expected a more simpler YAML format as,

name : hello
msgs:
   - hello
   - world

How can I force YAML to print list items with hypen + space notation instead of JSON like [a,b,c,d] notation?

Why does PyYAML print an Ordered dict item as [name, hello] and not as name : hello?

2 Answers
Related