Preserve case in ConfigParser?

前端 未结 5 1843
闹比i
闹比i 2020-12-04 23:00

I have tried to use Python\'s ConfigParser module to save settings. For my app it\'s important that I preserve the case of each name in my sections. The docs mention that pa

5条回答
  •  伪装坚强ぢ
    2020-12-04 23:43

    The documentation is confusing. What they mean is this:

    import ConfigParser, os
    def get_config():
        config = ConfigParser.ConfigParser()
        config.optionxform=str
        try:
            config.read(os.path.expanduser('~/.myrc'))
            return config
        except Exception, e:
            log.error(e)
    
    c = get_config()  
    print c.options('rules')
    

    I.e. override optionxform, instead of calling it; overriding can be done in a subclass or in the instance. When overriding, set it to a function (rather than the result of calling a function).

    I have now reported this as a bug, and it has since been fixed.

提交回复
热议问题