ConfigParser reads capital keys and make them lower case

前端 未结 1 1087
旧时难觅i
旧时难觅i 2021-01-30 12:45

I found one interesting observation. I had written one config file read program as,

import ConfigParser
class  ConfReader(object):
    ConfMap = dict()

    def          


        
相关标签:
1条回答
  • 2021-01-30 12:51

    ConfigParser.ConfigParser() is a subclass of ConfigParser.RawConfigParser(), which is documented to behave this way:

    All option names are passed through the optionxform() method. Its default implementation converts option names to lower case.

    That's because this module parses Windows INI files which are expected to be parsed case-insensitively.

    You can disable this behaviour by replacing the RawConfigParser.optionxform() function:

    self.config = ConfigParser.ConfigParser()
    self.config.optionxform = str
    

    str passes through the options unchanged.

    0 讨论(0)
提交回复
热议问题