I have a python project where I would like to use YAML (pyYaml 3.11), especially because it is “beautiful” and convenient for users to edit in a text editor, if and when necessary. My problem, however, is that if I bring YAML into a python application (as I need) and edit the contents (as I need), then writing a new document is usually not as beautiful as what I am began.
The pyyaml documentation is pretty poor - it doesn't even document the parameters of the dump function. I found http://dpinte.wordpress.com/2008/10/31/pyaml-dump-option/ . However, I still lack the necessary information. (I started looking at the source, but this does not seem the most attractive. If I do not get a solution here, then this is my only resource.)
I start with a document that looks like this:
- color green:
inputs:
- port thing:
widget-hint: filename
widget-help: Select a filename
- port target_path:
widget-hint: path
value: 'thing'
outputs:
- port value:
widget-hint: string
text: |
I'm lost and I'm found
and I'm hungry like the wolf.
After loading in python (yaml.safe_load (s)), I will try a couple of ways to reset it:
>>> print yaml.dump (d3, default_flow_style = False, default_style = '')
- color green:
inputs:
- port thing:
widget-help: Select a filename
widget-hint: filename
- port target_path:
value: thing
widget-hint: path
outputs:
- port value:
widget-hint: string
text: 'I''m lost and I''m found
and I''m hungry like the wolf.
'' >>> print yaml.dump (d3, default_flow_style = False, default_style = '|')
- "color green":
"inputs":
- "port thing":
"widget-help": | -
Select a filename
"widget-hint": | -
filename
- "port target_path":
"value": | -
thing
"widget-hint": | -
path
"outputs":
- "port value":
"widget-hint": | -
string
"text": |
I'm lost and I'm found
and I'm hungry like the wolf.
Ideally, I would like the “short lines” not to use quotation marks, as in the first result. But I would like multiline lines to be written as blocks, as in the second result. I think, in principle, I'm trying to minimize the explosion of unnecessary quotes in a file, which, in my opinion, will make it much more annoying for editing in a text editor.
Does anyone have any experience?