3

If I run the following script:

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()

the output is:

keyword1 = the value
keyword2 = "'the value'"
keyword3 = '"the value"'

Is there any way to produce the following output?

keyword1 = 'the value'
astrofrog
  • 32,883
  • 32
  • 90
  • 131

2 Answers2

4

What you're after is unrepr=True

config = ConfigObj(unrepr=True)

Then quotes will be preserved when you write back to file.

PartialOrder
  • 2,870
  • 3
  • 36
  • 44
0

I've never used the ConfigObj module, however from the documentation it appears that you may be able to achieve this by passing the interpolation argument when instantiating the ConfigObj.

Try:

config = ConfigObj(interpolation = 'Template')

or

config = ConfigObj(interpolation = False) 
garnertb
  • 9,454
  • 36
  • 38