Sorry, I am a newbie in Python and trying to work on the ConfigParser module. Here is one script which is used to read multiple sections and values from a .ini file and print them as below (Current output). Now, I would like to store each of these values of url, password into variables and use each of them to run REST call using a for loop.
What changes are required to store value of each "url" and "password" into different variables?
# cat file.ini
[bugs]
url = http://localhost:1010/bugs/
username = mark
password = SECRET
[wiki]
url = http://localhost:1010/wiki/
username = chris
password = PWD
Script :-
from ConfigParser import SafeConfigParser
parser = SafeConfigParser()
parser.read('file.ini')
for element in parser.sections():
print 'Section:', element
print ' Options:', parser.options(element)
for name, value in parser.items(element):
print ' %s = %s' % (name, value)
print
Current output :-
~]# python parse.py
Section: wiki
Options: ['url', 'username', 'password']
url = http://localhost:1010/wiki/
username = chris
password = PWD
Section: bugs
Options: ['url', 'username', 'password']
url = http://localhost:1010/bugs/
username = mark
password = SECRET