Python config module

Python config module is a hierarchical, easy-to-use, powerful configuration module for Python.
Download

Python config module Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Freely Distributable
  • Price:
  • FREE
  • Publisher Name:
  • Vinay Sajip
  • Publisher web site:
  • http://www.red-dove.com/python_config.html

Python config module Tags


Python config module Description

Python config module is a hierarchical, easy-to-use, powerful configuration module for Python. Python config module allows a hierarchical configuration scheme with support for mappings and sequences, cross-references between one part of the configuration and another, the ability to flexibly access real Python objects without full-blown eval(), an include facility, simple expression evaluation, and the ability to change, save, cascade, and merge configurations.It interfaces easily with environment variables and command line options. Python config module has been developed on Python 2.3, but should work on version 2.2 or greater.UsageThe simplest scenario is, of course, "Hello, world". Let's look at a very simple configuration file simple.cfg where a message to be printed is configured:# The message to print (this is a comment)message: 'Hello, world!'and the program which uses it:from config import Config# You can pass any file-like object; if it has a name attribute,# that name is used when file format error messages are printedf = file('simple.cfg')cfg = Config(f)print cfg.messagewhich results in the expected:Hello, world!A configuration file is, at the top level, a list of key-value pairs. Each value, as we'll see later, can be a sequence or a mapping, and these can be nested without any practical limit.In addition to attribute access (cfg.message in the example above), you can also access a value in the configuration using the getByPath method of a configuration: cfg.getByPath('message') would be equivalent. The parameter passed to getByPath is the path of the required value. The getByPath method is useful for when the path is variable. It could even be read from a configuration.There is also a get method which acts like the dictionary method of the same name - you can pass a default value which is returned if the value is not found in the configuration. The get method works with dictionary keys or attribute names, rather than paths. Hence, you may call cfg.getByPath('a.b') which is equivalent to cfg.a.b, or you can call cfg.a.get('b', 1234) which will return cfg.a.b if it is defined, and 1234 otherwise.What's New in This Release:· This release adds Mapping.__delitem__, makes Mapping.__getattribute__ no longer return "" when asked for "__class__" (doing so causes pickle to crash), and allows negative numbers.


Python config module Related Software