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!