如果我运行以下脚本:
from configobj import ConfigObj
config = ConfigObj()
config.filename = 'test.cfg'
config['keyword1'] = "the value"
config['keyword2'] = "'{0:s}'".format("the value")
config['keyword3'] = '"{0:s}"'.format("the value")
config.write()
输出为:
keyword1 = the value
keyword2 = "'the value'"
keyword3 = '"the value"'
有没有办法产生以下输出?
keyword1 = 'the value'
你所追求的就是unrepr=True
config = ConfigObj(unrepr=True)
然后,当您写回文件时,引号将被保留。
我从未使用过 ConfigObj 模块,但是从文档中可以看出,您可以通过在实例化 ConfigObj 时传递插值参数来实现这一点。
尝试:
config = ConfigObj(interpolation = 'Template')
或
config = ConfigObj(interpolation = False)