| Home | Trees | Index | Help |
|
|---|
| Package amplee :: Module loader :: Class Config |
|
object --+
|
Config
Represents an INI file as a tree of Config instances
Say you have ``test.conf``:
[general] verbose = True
>>> from amplee.loader import Config
>>> config = Config()
>>> config.from_ini('test.conf')
>>> print config.general.verbose
>>> True
Each loaded value is an unicode object except the following strings: 'True' --> True 'False' --> False 'None' --> None
An empty string will not be transformed into a None though.| Method Summary | |
|---|---|
Loads the configuration file into the current instance of `Config`. | |
Retrieve the value for a particular node in the configuration tree. | |
Returns a dictionnary of all nodes which parent is the section. | |
get_section(self,
section)
| |
| Inherited from object | |
x.__init__(...) initializes x; see x.__class__.__doc__ for signature | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
x.__hash__() <==> hash(x) | |
T.__new__(S, ...) -> a new object with type S, a subtype of T | |
helper for pickle | |
helper for pickle | |
x.__repr__() <==> repr(x) | |
x.__setattr__('name', value) <==> x.name = value | |
x.__str__() <==> str(x) | |
| Method Details |
|---|
from_ini(self, filepath, encoding='ISO-8859-1')Loads the configuration file into the current instance of `Config`. The ``filepath`` is the path to the configuration file. The ``encoding`` indicates how to decode each value. |
get(self, section, option, default=None, raise_error=False)Retrieve the value for a particular node in the configuration tree.
>>> print config.get('general', 'verbose', default=1)
but also:
>>> try:
>>> config.get('general', 'verbose', raise_error=True)
>>> except AttributeError:
>>> print 'Could not find it'
The ``section`` is the name of the parent node of which ``option`` is a child. The ``option`` is the name of the node to lookup. You can provide a ``default`` value when the node was not found. This applies when ``raise_error`` is ``False``, which is the default. If you set ``raise_error`` to ``True`` an ``AttributeError`` exception will be raised if the node is not found. |
get_all_values(self, section, capitalize=False)Returns a dictionnary of all nodes which parent is the section. The ``section`` is the name of the parent node to look for. The ``capitalize`` parameter indicates if the keys of the returned dictionnary should start with a cpital letter. |
| Home | Trees | Index | Help |
|
|---|
| Generated by Epydoc 2.1 on Thu Jul 19 15:32:17 2007 | http://epydoc.sf.net |