https://github.com/abg/misc
my dumping ground for code ideas
https://github.com/abg/misc
Last synced: 3 months ago
JSON representation
my dumping ground for code ideas
- Host: GitHub
- URL: https://github.com/abg/misc
- Owner: abg
- Created: 2010-05-06T00:48:57.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2011-01-22T08:26:52.000Z (over 14 years ago)
- Last Synced: 2025-01-02T09:23:37.458Z (5 months ago)
- Language: Python
- Homepage:
- Size: 148 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
config4py
=========config4py is a simple config library that handles ini-like
config files as python dicts.config4py supports configspecs in a very similar fashion to
_ConfigObj: http://www.voidspace.org.uk/python/configobj.htmlExamples
++++++++Basic config syntax:
simple.conf:
[config]
foo = bar
# config4py supports %include directives
%include extended.confextended.conf:
[config]
bar = baz
[other]
boz = foobarbaz>>> from config4py import Config
>>> Config.read(['simple.conf'])
{'config': {'foo': u'override'}, 'other': {'boz': u'foo,bar,baz'}}Validate simple dictionary values:
>>> from config4py import Config, Configspec
>>> cfg = Config({ 'port' : '3306' })
>>> cfgspec = Configspec({ 'port' : 'integer' })
>>> cfgspec.validate(cfg)
{'port': 3306}Validate a config file:
example.conf:
[example]
exclude-list = foo, bar, baz>>> from config4py import Config, Configspec
>>> cfg = Config.read(['example.conf'])
>>> spec = Configspec({ 'example' : { 'exclude-list' : 'list' } })
>>> spec.validate(cfg)
{'example': {'exclude-list': [u'foo', u'bar', u'baz']}}