这就是PyYAML在我的机器上的行为:
>>> plan = {'Business Plan': ['Collect Underpants', '?', 'Profit']}
>>> print(yaml.dump(plan))
Business Plan: [Collect Underpants, '?', Profit]
我想要的是这个输出(两者都是有效的YAML):
Business Plan:
- Collect Underpants
- '?'
- Profit
是否有某种选择可以做到这一点?
答案 0 :(得分:1)
您需要在调用中添加'default_flow_style = False'参数:
In [6]: print(yaml.dump(plan, default_flow_style=False))
Business Plan:
- Collect Underpants
- '?'
- Profit