config.ini文件
[config]
username = 2024222222
password = 123456
time = 202320241
num1 = 1
id1 = 018819
num2 = 1
id_1 = 018818
读取配置文件
def read_ini():
file = 'config.ini'
con = configparser.ConfigParser()
con.read(file, encoding='utf-8')
item = con.items('config')
item = dict(item)
print(item)
semester = item['time'] # 获取配置文件中的学期
print(semester)
写入配置文件
def write_ini():
file = 'config.ini'
con = configparser.ConfigParser()
con.read(file, encoding='utf-8')
con.set('config', 'username', '111111111111111111111111111')
con.set('config', 'password', '123456465')
with open(file, 'w') as f:
con.write(f)
username 与 password 对应的值已改变
其它
也可以用json或者yaml
标签:配置文件,item,ini,file,使用,configparser,config,con From: https://www.cnblogs.com/code3/p/18537689