I am using the yaml module in my Python script to generate a YAML file. The following is an example:
import yaml
class MyDumper(yaml.Dumper):
def increase_indent(self, flow=False, indentless=False):
return super(MyDumper, self).increase_indent(flow, False)
foo = {
'instance_type': 'test',
'hostname': "\"testhost\"",
'name': 'foo',
'my_list': [
{'foo': 'test', 'bar': 'test2'},
{'foo': 'test3', 'bar': 'test4'}],
'hello': 'world',
}
print yaml.dump(foo, Dumper=MyDumper, default_flow_style=False)
Output:
hello: world
hostname: '"testhost"'
instance_type: test
my_list:
- bar: test2
foo: test
- bar: test4
foo: test3
name: foo
In above output hostname value has single and double quotes, I want only double quotes.
Expected output:
hello: world
hostname: "testhost"
instance_type: test
my_list:
- bar: test2
foo: test
- bar: test4
foo: test3
name: foo