python读写ini
from configparser import *
ini = ConfigParser()
# 读入文件
ini.read("res/test.ini", encoding="utf-8")
# 打印
for section in ini.sections():
print("\n[" + section + "]")
for option in ini.options(section):
print(option + " = " + ini[section][option])
# 添加记录
if (ini.has_section("default") == False):
ini.add_section("default")
ini.set("default", "abc", "你好吗")
# 写入文件
ini.write(open("res/test.ini", "w", encoding="utf-8"))
del ini