python3 ini file reading and writing

 

import  configparser
  
config = configparser.ConfigParser()
file = 'config.ini'
config.read(file)
config.add_section('login')
config.set('login','username','1111')
config.set('login','password','2222')
with open(file,'w') as configfile:
    config.write(configfile)


config = configparser.ConfigParser()
file = 'config.ini'
config.read(file)
username = config.get('login','username')
password = config.get('login','password')
print(username,password)

 

Guess you like

Origin www.cnblogs.com/sea-stream/p/11861039.html