开发者

Change list formatting in PyYAML output

开发者 https://www.devze.com 2022-12-20 15:44 出处:网络
This is how PyYAML behaves on my machine: >>> plan = {\'Business Plan\': [\'Collect Underpants\', \'?\', \'Profit\']}

This is how PyYAML behaves on my machine:

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

What I want instead is this output (both is valid YA开发者_开发问答ML):

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

Is there some kind of option that would do it?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号