28 lines
678 B
Python
28 lines
678 B
Python
![]() |
import configparser
|
||
|
from clog import logger
|
||
|
|
||
|
"""
|
||
|
修改配置文件中的指定参数。
|
||
|
|
||
|
参数:
|
||
|
s (str): 配置文件中的节(section)名称。
|
||
|
o (str): 配置文件中的选项(option)名称。
|
||
|
v (str): 要设置的新值。
|
||
|
|
||
|
返回值:
|
||
|
无
|
||
|
"""
|
||
|
def change_config_ini(s, o, v):
|
||
|
|
||
|
# 读取配置文件
|
||
|
config = configparser.ConfigParser()
|
||
|
config.read("config.ini", encoding="utf-8") # 解决可能的编码问题
|
||
|
|
||
|
# 修改参数
|
||
|
config.set(s, o, v)
|
||
|
|
||
|
# 将修改后的配置写回文件
|
||
|
with open("config.ini", "w", encoding="utf-8") as configfile:
|
||
|
config.write(configfile)
|
||
|
|
||
|
logger.info(f"{s}.{o} 参数已更新为 {v}")
|