Cerin
Cerin

Reputation: 64799

How to force specific Yaml list type

How do you force the dump() method in Python's yaml implementation to use the one-element-per-line list style?

e.g. When I do yaml.dump([1,2,3]) I get "[1, 2, 3]\n" when I actually want:

- 1
- 2
- 3

Upvotes: 2

Views: 464

Answers (1)

mgibsonbr
mgibsonbr

Reputation: 22007

You can use default_flow_style:

>>> print yaml.dump([1,2,3], default_flow_style=False)
- 1
- 2
- 3

Upvotes: 2

Related Questions