Formatting 更改PyYAML输出中的列表格式

Formatting 更改PyYAML输出中的列表格式,formatting,python-3.x,pyyaml,Formatting,Python 3.x,Pyyaml,这就是PyYAML在我的机器上的行为: >>> plan = {'Business Plan': ['Collect Underpants', '?', 'Profit']} >>> print(yaml.dump(plan)) Business Plan: [Collect Underpants, '?', Profit] 我想要的是这个输出(两者都是有效的YAML): 是否有某种选项可以做到这一点?您需要在调用中添加“default\u flow\u s

这就是PyYAML在我的机器上的行为:

>>> plan = {'Business Plan': ['Collect Underpants', '?', 'Profit']}
>>> print(yaml.dump(plan))
Business Plan: [Collect Underpants, '?', Profit]
我想要的是这个输出(两者都是有效的YAML):


是否有某种选项可以做到这一点?

您需要在调用中添加“default\u flow\u style=False”参数:

In [6]: print(yaml.dump(plan, default_flow_style=False))
Business Plan:
- Collect Underpants
- '?'
- Profit
In [6]: print(yaml.dump(plan, default_flow_style=False))
Business Plan:
- Collect Underpants
- '?'
- Profit