How can I read /etc/config.d/... with python?
Question: I want distros to pick up my python app so they can make a /etc/myapp config
file and a /etc/myapp.d/ folder, where users can put their configs over
overwrite settings in /etc/myapp.

It should support the following (more or less standard) configuration style.

    
    
    # settingx does ...
    settingx=1
    
    settingy = 0
    
    settingz = "--this x --that y"
    

And in my python app I want to use settingx, settingy etc.

What's the best way to do it?


Answer: Use [`ConfigParser`](http://docs.python.org/2/library/configparser.html) as
this is an accepted settings exchange format that is baked into the python
distribution.

    
    
    import ConfigParser
    
    config = ConfigParser.RawConfigParser()
    
    config.add_section('myapp')
    config.set('myapp', 'settingx', 1)
    config.set('myapp', 'settingy ', 0)
    config.set('myapp', 'settingz ', '--this x --that y')
    
    # Writing our configuration file to 'example.cfg'
    with open('/etc/myapp/example.cfg', 'wb') as configfile:
        config.write(configfile)
    

