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)

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/11861039.html
今日推荐