سؤال

هذا هو كيف 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=False' حجة على الدعوة:

In [6]: print(yaml.dump(plan, default_flow_style=False))
Business Plan:
- Collect Underpants
- '?'
- Profit
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top