Title: configparse module in python3 can not write '%' to config file
Type: behavior Stage:
Components: Versions: Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: lukasz.langa, quanyechavshuo
Priority: normal Keywords:

Created on 2017-06-26 09:48 by quanyechavshuo, last changed 2017-07-12 12:08 by lukasz.langa.

Messages (2)
msg296865 - (view) Author: quanyechavshuo (quanyechavshuo) Date: 2017-06-26 09:48
Hello,I was using configparser module in python3.6,but find it works not good when I try to write '%' to my config file,below is my func:

def update_config_file_key_value(file, section, key_name, key_value):
    # 通过configparser模块的调用更新配置文件
    # section是[]里面的值
    if os.path.exists(file) == False:
        os.system("touch %s" % file)
    import configparser
    config = configparser.ConfigParser()
    sectionList = config.sections()
    if section not in sectionList:
    config.set(section, key_name, str(key_value))
    with open(file, 'w') as f:

When I use it as:
it works well,but below not ok:
and below not ok:
and below not ok:

That's to say,configparser can not write '%' to config file.
msg298204 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2017-07-12 12:08
With the default ConfigParser, we're using basic interpolation, as covered by:

To not have it, set interpolation to None in the ConfigParser constructor:

    config = configparser.ConfigParser(interpolation=None)

Then percent signs will be treated like any other character. Let me know if you have further questions.
Date User Action Args
2017-07-12 12:08:13lukasz.langasetmessages: + msg298204
2017-06-29 18:41:36r.david.murraysetnosy: + lukasz.langa
2017-06-26 09:48:10quanyechavshuocreate