Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Write YAML file from python dict containing special characters (asterisk, ampersand, *, &)

$
0
0

I have a YAML file, that I need to import to python, process it in some way and then export as YAML file again. More precisely I import YAML config file as a dict, generate many files with altering parameters and then write them all as YAML files again.

The problem I facing is that there are parameters with special characters ($, &) before them: e.g. *target_size.

When I'm working with a dict in python, then this parameter is a dictionary value in a string format ('*target_size'). When I'm writing this dict as YAML file formatting get preserved, i.e. '*target_size' is encircled by quotes in resulting YAML file. What I need is just *target_size, same as in the original file.

I've looked pyYaml docs and other resources but didn't found the solution.

Code to write YAML file:

    with open(f'{PATH}/base_config.yml', 'w') as outfile:         yaml.dump(config, outfile, default_flow_style=False, sort_keys=False)

original YAMLpython dictresulting file


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>