Adding data to a YAML file using Python

I am trying to write a dictionary value to a YAML file.

The dictate is:

data_dict = {'BACKENDTYPE' :{ 'BACKENDNAME' : 'BACKENDPATH'}}

      

Update code:

with open(backend_config_file,'w')as yaml_file:
            yaml_file.write(yaml.dump(data_dict , default_flow_style=False))

      

The problem is it will always overwrite the YAML file and not add the dictionary.

Is there a way to add the data or the data should be treated like the dict itself and the resulting dictionary, fully preserved?

+3
python pyyaml


source to share


No one has answered this question yet

See similar questions:

1414
How do you add a file in Python?

or similar:

5504
Does Python have a ternary conditional operator?
5231
What are metaclasses in Python?
5116
How can I check if a file exists without exceptions?
4473
Calling an external command in Python
3790
How can I safely create a subdirectory?
3602
Does Python have a substring method "contains"?
3474
How to list all files in a directory?
3119
What is the difference between Python list methods that are appended and expanded?
1414
How do you add a file in Python?
585
open () in Python doesn't create a file if it doesn't exist



All Articles
Loading...
X
Show
Funny
Dev
Pics