记录一下,方便用时查找
# coding:utf-8
import configparser
# ini文件路径
inipath = 'Config.ini'
cf = configparser.ConfigParser()
cf.read(inipath)
# selection 节点
# key 键
# value 值
# 写
def writeini(selection, key, value):
try:
try:
cf.add_section(selection)
except:
pass
cf.set(selection, key, value)
cf.write(open(inipath, 'w'))
return True
except:
return False
# 读取
def readini(selection, key):
try:
cf.read(open(inipath))
result = cf.get(selection, key)
return result
except:
return None
# 修改
def updateini(selection, key, value):
try:
cf.read(inipath)
cf.set(selection, key, value)
cf.write(open(inipath, "r+"))
return True
except:
return False