import configparser
def set_value_in_property_file(file_path, section, key, value):
config = configparser.RawConfigParser()
config.read(file_path)
config.set(section,key,value)
cfgfile = open(file_path,'w')
config.write(cfgfile, space_around_delimiters=True) # use flag in case case you need to avoid white space.
cfgfile.close()
set_value_in_property_file("sample.ini","Test","name1","32")
python 更改配置文件 key value 值
最新推荐文章于 2023-04-21 16:36:18 发布
本文介绍如何使用Python的configparser模块在'sample.ini'中设置section 'Test'的key 'name1'为'value32',并演示了写入配置文件的过程。
2740

被折叠的 条评论
为什么被折叠?



