最简单的方法是用configparser 库,configparser 是 Python 标准库的一部分,用于读取和写入配置文件(通常是 .ini 格式的文件)。废话少说,直接上code
# update the ini file
def UpdateIni(inifile: str, group: str, key: str, value: str) -> None:
ini = configparser.ConfigParser()
ini.read(inifile)
ini.set(group, key, value)
with open(inifile, 'w', encoding="utf-8") as configfile:
ini.write(configfile)
# end with
del ini
#end def
最后, 记得import
import configparser # Ini file create/read
1万+

被折叠的 条评论
为什么被折叠?



