I have been tasked with creating a program that will update a value in an ini file. The ini file looks like;
[link1]
name = nodeB
ip = 127.0.0.1
port = 1002
cost = 190
[link2]
name = nodeC
ip = 127.0.0.1
port = 1003
cost = 210
The command to update this ini file can only take two parameters, neighbor name and cost. I cant figure out how to update the values without saying which section the neighbor is in. The example of the parameters in use is UpdateRouteCost
nodeB 4.
I am able to update a value by stating the section and the key I want updated.
elif text == "UpdateRouteCost":
parser = configparser.ConfigParser()
parser.read('try.ini')
t = open('try.ini', 'w')
parser.set('link1', 'cost', '1')
parser.write(t)
t.close()
print(parser.get('link1', 'cost'))