python3 ini文件读写

 

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)

 

posted @ 2019-11-14 19:41  anobscureretreat  阅读(1187)  评论(0编辑  收藏  举报