I have a cfg file. In that cfg file there is a line like:
[Environment]
automation_type=GFX ;available options: GEM, HEXAII
I want to modify this line by:
[Environment]
automation_type=ABC ;available options: GEM, HEXAII
I have written the below code for this:
get_path_for_od_cfg = r"C:\Users\marahama\Desktop\Abdur\abc_MainReleaseFolder\OD\od\odConfig.cfg"
config = ConfigParser.RawConfigParser()
config.read(get_path_for_OpenDebug_cfg)
for sec in config.sections():
for attr in config.options(sec):
if sec =='Environment' and attr == 'automation_type':
config.set('Environment','automation_type','ABC')
with open(get_path_for_OpenDebug_cfg, 'wb') as configfile:
config.write(configfile)
After executing the code, I get
[Environment]
automation_type = ABC
";available options: GEM, HEXAII" this line is missing.
RawConfigParserobjects store comments.