更改列表中PyYAML输出格式
-
21-09-2019 - |
题
这是PyYAML我的机器上的行为:
>>> plan = {'Business Plan': ['Collect Underpants', '?', 'Profit']}
>>> print(yaml.dump(plan))
Business Plan: [Collect Underpants, '?', Profit]
我想是代替这个输出(二者是有效YAML):
Business Plan:
- Collect Underpants
- '?'
- Profit
是否有某种选项,会做呢?
解决方案
您需要添加“default_flow_style =假”参数调用:
In [6]: print(yaml.dump(plan, default_flow_style=False))
Business Plan:
- Collect Underpants
- '?'
- Profit
不隶属于 StackOverflow