-1

I want to make one YAML file by Python like as below.

A:
  B:
     c: {d:e}

but if I do it like as below:

data = {'A':{'B':{ 'c':'{d:e}'}}}
yaml.dump(data,file,default_flow_style = False)

the output in the file is as below:

A:
  B:
    c: '{d: e}'

I don't want the quotation around. How to do it?

Anthon
  • 69,918
  • 32
  • 186
  • 246
subhadip
  • 39
  • 5
  • Why do you think that's not the right output? Note that YAML's mappings (or [*"associative arrays"*](https://en.wikipedia.org/wiki/YAML#Associative_arrays)) don't look like dictionaries. – jonrsharpe Sep 27 '15 at 09:27

1 Answers1

0

You made a string out of {d:e} by putting quotes around the whole thing. Change '{d:e}' to {'d':'e'}.

In [57]: data = {'A':{'B':{ 'c':{'d':'e'}}}}

In [58]: print yaml.dump(data)
A:
  B:
    c: {d: e}
Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214