boodebr.configedit frank, 03 August 2008 (created 11 November 2007) Tags:config
boodebr.config provides configuration files in the spirit of .INI files, but using either JSON or XML. It provides a more flexible and easier to use API than Much more flexible and easier to use than ConfigParser
The main entry point is the configfile factory function:
Configuration filename (does not have to exist). Guarantees not to create the file until you add data.
format
'json' or 'xml' (will be autodetected when reading; this specifies the format to write).
allow_dict
True/False - should set() allow you to pass a dict? (The downside of setting this to 'True' is a larger/more verbose configuration file, so only use this you really need it.)
Returns a configuration object.
You get and set data with simple path:key pairs. Here is a short example that demonstrates the API:
from boodebr.config import configfile
# a test object -- subtlety here, must define before calling 'configfile()' # since it will immediately try to deserialize the configfile (if it exists) class Foo(object): def __init__(self, a, b): self.a = a self.b = b
# create config file in JSON format cfg = configfile('test.json', 'json')