I'm using ruamel.yaml
for modifying a YAML file. My requirement is to add a value for an existing key, preserving everything else including the order. I got it to work, but looks like quotation marks of other keys/values get modified too in the process.
For some cases, double quotes get converted to single quotes. E.g.
Before
node_js: - "0.10"
After
node_js: - '0.10'
In some other cases, quotes get dropped altogether. E.g.:
Before
before_script: - "cp test/config-x.js src/config.js"
After
before_script: - cp test/config-x.js src/config.js
Both of these cases appear in the same file. How can I stop this from happening and preserve the quotes as it is in the original?
I use load_yaml_guess_indent()
for loading and round_trip_dump()
for writing it back.
load_yaml_guess_indent()
, you can specifypreserve_quotes=True
for that function as well, that argument will be passed on to theround_trip_load()
function – Normadata, ind, bsi = load_yaml_guess_indent(open(file_name),preserve_quotes=True)
gets me aTypeError: YAML.load() got an unexpected keyword argument 'preserve_quotes'
error. am i missing something? – Podium