Preserve quotes and also add data with quotes in Ruamel
问题 I am using Ruamel to preserve quote styles in human-edited YAML files. I have example input data as: --- a: '1' b: "2" c: 3 I read in data using: def read_file(f): with open(f, 'r') as _f: return ruamel.yaml.round_trip_load(_f.read(), preserve_quotes=True) I then edit that data: data = read_file('in.yaml') data['foo'] = 'bar' I write back to disk using: def write_file(f, data): with open(f, 'w') as _f: _f.write(ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper, width=1024)) write_file