这是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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top