最简单的方法是用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

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐