Variazione lista formattazione in uscita PyYAML
-
21-09-2019 - |
Domanda
Questo è come si comporta PyYAML sulla mia macchina:
>>> plan = {'Business Plan': ['Collect Underpants', '?', 'Profit']}
>>> print(yaml.dump(plan))
Business Plan: [Collect Underpants, '?', Profit]
Quello che voglio invece è questa uscita (entrambi è YAML valido):
Business Plan:
- Collect Underpants
- '?'
- Profit
C'è una sorta di opzione che lo farebbe?
Soluzione
È necessario aggiungere il 'default_flow_style = False' argomento per la chiamata:
In [6]: print(yaml.dump(plan, default_flow_style=False))
Business Plan:
- Collect Underpants
- '?'
- Profit
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow