Python configparser

From wikinotes

Python comes included with the ConfigParser module which can easily process simple user-settings/preferences. (Foranything more complicated, a database is still the way to go).

Sample Config

#### /home/will/dev/temp.conf

## this section is for cars
[Section A]
Wheels  : round
Gas     : butane
Farts   : smelly

## This section is for other stuff
[Section B]
Category : uncategorized
Speakers : none

[Section C]
Combine 1 : ${Section A:Wheels}, ${Section B:Category}
####

Usage

import ConfigParser
cfg = ConfigParser.ConfigParser()

cfg.read('/home/will/dev/temp.conf')				## Load Config

cfg.sections()												## Sections in loaded file
cfg.get("Section A", "Gas")							## Query value
cfg.set("Section A", "Gas", "none")					## Set value (always write/close after)


file = '/home/will/dev/temp.conf'					## set new file to be written
cfg.add_section('SectionA')							## add section to file
cfg.set('SectionA', 'Gas'  , 'none')				## set value
cfg.set('SectionA', 'Miles', 'none')				## set value
cfg.write(file)											## write new values
file.close()												## close file