Support capital letters Python standard components ConfigParser configuration file parser, save the configuration method when

Although it has been used in xml configuration file as the preferred format, but sometimes still need to parse ini, cfg file (for compatibility with earlier versions of software or other authors).

Basically Python comes ConfigParser enough to deal with, but the fly in the ointment is that, configparser.RawConfigParser.write () when you save the file, all the key will be saved as lowercase.

Such components should be designed to avoid mixed case led to the identification of the key difficulties, but if there is a particular need to customize the case, you can find the class RawConfigParser Python installation directory in Lib \ configparser.py file () method of optionxform:

class RawConfigParser(MutableMapping):
    ...
    ...
    def optionxform(self, optionstr):
        return optionstr.lower()
    ...

The function here lowercase lower () remove:

    def optionxform(self, optionstr):
        return optionstr

In this way, when then save the configuration file, key will not automatically become lowercase.

Guess you like

Origin www.cnblogs.com/gamesun/p/11089924.html