I have .conf file with Key Value pair like -
key1=value1
key2=value2
key3=value3
In my python code I have dictionary like
conf = {'key1' : 'newvalue1', 'key3' : 'newvalue3'}
I want to update value of given keys from dictionary in file by using python. How can I achieve it. I tried below but it is not working
def save_settings(conf):
for line in fileinput.input(files=["%s" % (CONF)], inplace=1):
line = re.sub('key1=.*', 'key1=%s' % (conf['key1']), line.rstrip())
line = re.sub('key3=.*', 'key1=%s' % (conf['key1']), line.rstrip())
print(line)
return "true"