forcing pyYAML to dump consistently

Question:

In [136]: a = [1,2,3,4,5]

In [137]: print yaml.dump(a)
[1, 2, 3, 4, 5]


In [138]: a = [1,2,3,4,5, [1,2,3]]

In [139]: print yaml.dump(a)
- 1
- 2
- 3
- 4
- 5
- [1, 2, 3]

why are the outputs of above two dumps different? Is it possible to force pyYAML to split the list always?

Asked By: Anuvrat Parashar

||

Answers:

From the documentation:

print yaml.dump(a, default_flow_style=False)

The value can be True, False, or None. If None or unspecified (that is, the default), it chooses automatically whether to use inline or block-style output. False never uses inline, True is always inline.

Answered By: marcus erronius
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.