pyyaml
pyyaml copied to clipboard
How does parameter `default_style` work?
I am using PyYAML 5.4.1 and I wonder how the optional paramter default_style
in the function yaml.dump
works. From other issues and part of the documentation, I guessed this parameter is to control the format of strings in dumpped document, and the possible values are '"'
, '|'
, '>'
and None
(as default) etc.
But I am getting unexpected formats of dumpped documents when using this parameter. For example, if I am to dump a simple dictionary:
>>> data = {'cases': [{'output': '0 10\n1 4', 'timeout': 1.0}]}
>>> print(yaml.dump(data, default_style='|'))
"cases":
- "output": |-
0 10
1 4
"timeout": !!float |-
1.0
Why are keys quoted in "
's? And why the value of timeout
is represented as string with extra !!float
tag? Is there a way to achieve the expected result:
cases:
- output: |-
0 10
1 4
timeout: 1.0
Thanks in advance, and apologies if GitHub issues are not the place for this kind of questions.