我正在使用 python3 ConfigParser,我的代码是
conf = configparser.ConfigParser()
cfg_file = open('./config.cfg', 'w')
conf.set(None, 'a', '0')
conf.write(cfg_file)
cfg_file.close()
我预计 config.cfg 文件中的结果为 a : 0
。但是,我得到了a = 0
。有没有办法将“=”替换为“:”?
最佳答案
使用分隔符参数来 ConfigParser
:
When `delimiters' is given, it will be used as the set of substrings that divide keys from values.
conf = configparser.ConfigParser(delimiters=':')
结果:
[DEFAULT]
a : 0
关于python - 如何在python中使用 ":"而不是 "="编写.cfg文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73703632/