0

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

>>> plan = {'Business Plan': ['Collect Underpants', '?', 'Profit']}
>>> print(yaml.dump(plan))
Business Plan: [Collect Underpants, '?', Profit]

我想要的是这个输出(两者都是有效的 YAML):

Business Plan:
- Collect Underpants
- '?'
- Profit

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

4

1 回答 1

1

You need to add the 'default_flow_style=False' argument to the call:

In [6]: print(yaml.dump(plan, default_flow_style=False))
Business Plan:
- Collect Underpants
- '?'
- Profit
于 2010-04-29T10:17:57.417 回答