Using ConfigParser to read a file without section name

前端 未结 7 2153
星月不相逢
星月不相逢 2020-11-27 03:36

I am using ConfigParser to read the runtime configuration of a script.

I would like to have the flexibility of not providing a section name (there are s

7条回答
  •  迷失自我
    2020-11-27 03:51

    You can use the ConfigObj library to do that simply : http://www.voidspace.org.uk/python/configobj.html

    Updated: Find latest code here.

    If you are under Debian/Ubuntu, you can install this module using your package manager :

    apt-get install python-configobj
    

    An example of use:

    from configobj import ConfigObj
    
    config = ConfigObj('myConfigFile.ini')
    config.get('key1') # You will get val1
    config.get('key2') # You will get val2
    

提交回复
热议问题