强制 pyYAML 持续转储 [英] forcing pyYAML to dump consistently
本文介绍了强制 pyYAML 持续转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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]
为什么以上两个 dumps
的输出不同?是否可以强制 pyYAML
始终拆分 list
?
why are the outputs of above two dumps
different? Is it possible to force pyYAML
to split the list
always?
推荐答案
来自文档:
print yaml.dump(a, default_flow_style=False)
该值可以是 True
、False
或 None
.如果 None
或未指定(即默认值),它会自动选择是使用内联还是块式输出.False
从不使用内联,True
总是内联.
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.
这篇关于强制 pyYAML 持续转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文