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

Problem while editing YAML/cfg file in Python

$
0
0

I'm using configparser in Python 3 to edit a file -

[conf]users: - william - bill - johnny

I want to add another value under users:.

My code is as follows-

from configparser import SafeConfigParserparser = SafeConfigParser()parser.read('config5.cfg')a = parser.get('conf', 'users')parser.set('conf', 'users', a +' hank')with open('config5.cfg', 'w') as f:    parser.write(f)

But instead of -

    users:     - william     - bill     - johnny     - hank

It becomes -

    users:     - william     - bill     - johnny hank

How can I fix this?

Thanks a lot!


Viewing all articles
Browse latest Browse all 5049

Trending Articles



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