1

I am using ConfigParser to edit my configuration file, but while updating the value in config file it ends up with removing all comments and converts all option values to lowercase from camelcase.

My Initial config file:

[Recording]

Record Video = Yes
Type = mp4 

# You can use [low/medium/high] all lowercase
Quality = medium

# The name of recording file.
Name = Recording

My python script

import configparser

CFG_FILENAME = 'config.txt'

cfg = configparser.RawConfigParser()
cfg.read(str(CFG_FILENAME))
cfgfile = open(str(CFG_FILENAME), 'w')
cfg.set('Recording', 'Record Video','No')
cfg.write(cfgfile)
cfgfile.close()

The Output file

[Recording]
record video = No
type = mp4
quality = medium
name = Recording

Please help me with this. Thanks in advance.

Ramesh Raghavan
  • 119
  • 2
  • 9

1 Answers1

2

Set this Option to preserve the case. Check here Preserve case in ConfigParser?

config.optionxform=str
Vignesh
  • 1,553
  • 1
  • 10
  • 25