def read_config(path=None):
if not path:
path = path_config
# notepad手动编辑toml文件, notepad默认编码"utf-8", open函数需指定encoding="utf-8", 内容均为字符串
# tomlkit.dumps函数生成的toml文件的默认编码"gbk", open函数默认encoding='gbk'
# str 转 tomlkit.toml_document.TOMLDocument 转 dict
# open().read()只能使用一次, 除非f.seek(0)将句柄放回文件的开头
with open(path, "r", encoding="utf-8") as f:
doc_config = tomlkit.parse(f.read())
dic_config = dict(doc_config)
print("已读取配置表:", dic_config)
return dic_config
notepad手动编辑toml文件, notepad默认编码"utf-8", open函数需指定encoding="utf-8", 内容均为字符串
tomlkit.dumps函数生成的toml文件的默认编码"gbk", open函数默认encoding='gbk'
str 转 tomlkit.toml_document.TOMLDocument 转 dict
open().read()只能使用一次, 除非f.seek(0)将句柄放回文件的开头