Configparser set with no section

后端 未结 3 487
悲&欢浪女
悲&欢浪女 2021-01-06 22:07

Is there a way for configparser in python to set a value without having sections in the config file?

If not please tell me of any alternatives.

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-06 22:51

    I know of no way to do that with configparser, which is very section-oriented.

    An alternative would be to use the Voidspace Python module named ConfigObj by Michael Foord. In the The Advantages of ConfigObj section of an article he wrote titled An Introduction to ConfigObj, it says:

    The biggest advantage of ConfigObj is simplicity. Even for trivial configuration files, where you just need a few key value pairs, ConfigParser requires them to be inside a 'section'. ConfigObj doesn't have this restriction, and having read a config file into memory, accessing members is trivially easy.

    Emphasis mine.

提交回复
热议问题