2

次のスクリプトを実行すると:

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'
4

2 に答える 2

3

あなたが求めているのはunrepr=True

config = ConfigObj(unrepr=True)

その後、ファイルに書き戻すときに引用符が保持されます。

于 2012-05-16T17:17:33.173 に答える
0

私は ConfigObj モジュールを使用したことがありませんが、ドキュメントから、ConfigObj をインスタンス化するときに補間引数を渡すことでこれを実現できるようです。

試す:

config = ConfigObj(interpolation = 'Template')

また

config = ConfigObj(interpolation = False) 
于 2012-04-22T11:14:22.820 に答える