I need to write the below data to yaml file using Python:
{A:a, B:{C:c, D:d, E:e}}
i.e., dictionary in a dictionary. How can I achieve this?
I need to write the below data to yaml file using Python:
{A:a, B:{C:c, D:d, E:e}}
i.e., dictionary in a dictionary. How can I achieve this?
The
default_flow_style=False
parameter is necessary to produce the format you want (flow style), otherwise for nested collections it produces block style:Link to the PyYAML documentation showing the difference for the
default_flow_style
parameter. To write it to a file in block mode (often more readable):produces: