如果我运行以下脚本:
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'发布于 2012-05-17 01:17:33
你要找的是unrepr=True
config = ConfigObj(unrepr=True)然后,当您写回文件时,将保留引用。
发布于 2012-04-22 19:14:23
我从未使用过ConfigObj模块,但是从documentation看,您可以通过在实例化ConfigObj时传递插值参数来实现这一点。
尝试:
config = ConfigObj(interpolation = 'Template')
或
config = ConfigObj(interpolation = False) https://stackoverflow.com/questions/10267253
复制相似问题