I am using Python function to create my config file and it is working fine once it is created successfully. I am opening that file to update the password key value and it is changing but it is changing other things as well. It is changing all CAPS keys into small and also changing ":" to "=". I am not sure why it is doing this.
nice.ini
:
[FILENAME]
FILE:nice.ini
[LOGFILE]
LOGFILE:*.log
[ENVIORNMENT]
KEEP_DEV:DEV
KEEP_IT:IT
KEEP_APP:APP
[NYCDEF]
NICE:
KEEP:0
dbname = NYCDEF
username = NICE_MAN
password = HELLO
[KGHINP]
NICE:
KEEP:0
dbname = KGHINP
username = NICE_MAN
password = HELLO
[NICDEF]
NICE:
KEEP:0
dbname = NICDEF
username = NICE_MAN
password = HELLO
function I am using to change the value of key password is:
from configparser import ConfigParser
parser = ConfigParser()
parser.read('nice.ini')
def update_Val():
while (True):
a = input("Do you want to update the pass of env?yes/no: ")
if a.lower() == "yes":
sect = input("Enter env name to update pass or q to exit : ")
if sect == 'q':
exit(120)
passwd = input("Enter pass to overwrite or q to exit : ")
if passwd == 'q':
exit(120)
parser.set(sect, 'password', passwd)
with open('nice.ini', 'w') as configfile:
parser.write(configfile)
configfile.close()
elif a.lower() == "no":
print("file updated")
break
update_value()
Once I run this function and change the value then it modify the file in below way. Here you can see all keys name turn to small and ":" changed to "=":
[FILENAME]
configfile = nice.ini
[LOGNAME]
logfile = delete.log
[ENVIORNMENT]
keep_dev = DEV
keep_it = IT
keeo_app = APP
[NYCDEF]
nice =
keep = 0
dbname = NYCDEF
username = NICE_MAN
password = HELLO
[KGHINP]
nice =
keep = 0
dbname = KGHINP
username = NICE_MAN
password = HELLO
[NICDEF]
nice =
keep = 0
dbname = NICDEF
username = NICE_MAN
password = HELLO