Change value in ini file using ConfigParser Python

后端 未结 3 1445
我在风中等你
我在风中等你 2021-02-05 14:20

So, I have this settings.ini :

[SETTINGS]

value = 1

And this python script

from ConfigParser import SafeConfigParser

parser =         


        
3条回答
  •  别跟我提以往
    2021-02-05 15:09

    Below example will help change the value in the ini file:

    PROJECT_HOME="/test/"
    parser = ConfigParser()
    parser.read("{}/conf/cdc_config.ini".format(PROJECT_HOME))
    parser.set("default","project_home",str(PROJECT_HOME))
    
    
    with open('{}/conf/cdc_config.ini'.format(PROJECT_HOME), 'w') as configfile:
        parser.write(configfile)
    
    [default]
    project_home = /Mypath/
    

提交回复
热议问题