kehuadong

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

 

posted on 2023-04-24 20:37  kehuadong  阅读(29)  评论(0编辑  收藏  举报

导航