我有一个cfg文件。在那个 cfg 文件中,有这样一行:
[Environment]
automation_type=GFX ;available options: GEM, HEXAII
我想通过以下方式修改这一行:
[Environment]
automation_type=ABC ;available options: GEM, HEXAII
我为此编写了以下代码:
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)
执行代码后,我得到
[Environment]
automation_type = ABC
";available options: GEM, HEXAII" this line is missing.