2

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'))
SuperShoot
  • 9,880
  • 2
  • 38
  • 55
Wayzival
  • 23
  • 3
  • For any one that is taking a look, thank you for your efforts. I achieved this by using parser.get to pull the values for name in both links, assigning them to variables. I then used if variable == to the users input for 'name' to update the correct link. – Wayzival Mar 29 '19 at 21:16

0 Answers0