carputils
Doxygen code documentation for the python framework controlling openCARP
Public Member Functions | List of all members
carputils.settings.namespace.SettingsNamespace Class Reference

Settings namespace object. More...

Inheritance diagram for carputils.settings.namespace.SettingsNamespace:
carputils.settings.paths.PathSettingsNamespace

Public Member Functions

def __init__ (self, missing_error=True, errortype=AttributeError)
 
def get (self, key, fallback=None)
 Get an item without raising errors when missing, like dict().get() More...
 
def __getattr__ (self, attr)
 Custom attribute access code providing case-insensitivity. More...
 
def __getitem__ (self, key)
 Allow object to be used like dict. More...
 
def __setattr__ (self, attr, value)
 Custom attribute access code providing case-insensitivity and order logging. More...
 
def __setitem__ (self, key, value)
 Allow object to be used like dict. More...
 
def __iter__ (self)
 Return iterator over settings. More...
 
def __str__ (self)
 

Detailed Description

Settings namespace object.

Objects of this class provide a case-insensitive namespace, which can be access either through attributes or as a dict. For example, an object created like:

>>> sn = SettingsNamespace()

can then be assigned values like::

>>> sn.MYPATH = '/some/path'
>>> sn['otherpath'] = '/other/path'

and accessed like:

>>> print sn['MYPATH']
'/some/path'
>>> print sn.otherpath
'/other/path'

Attributes/keys are case insensitive:

>>> print sn.mypath
'/some/path'
>>> print sn['OtherPath']
'/other/path'

Use of the attribute method of accessing values is recommended, as this reflects the object's intended use as a container of 'constants' in the rest of the code. dict-like access is implemented for backwards compatibility.

Parameters

missing_error bool, optional Raise an Exception when a requested attribute is missing or None (default: True) errortype Exception, optional Type of exception to raise when an item is missing or None (default; AttributeError)

Constructor & Destructor Documentation

◆ __init__()

def carputils.settings.namespace.SettingsNamespace.__init__ (   self,
  missing_error = True,
  errortype = AttributeError 
)

Member Function Documentation

◆ __getattr__()

def carputils.settings.namespace.SettingsNamespace.__getattr__ (   self,
  attr 
)

Custom attribute access code providing case-insensitivity.

◆ __getitem__()

def carputils.settings.namespace.SettingsNamespace.__getitem__ (   self,
  key 
)

Allow object to be used like dict.

◆ __iter__()

def carputils.settings.namespace.SettingsNamespace.__iter__ (   self)

Return iterator over settings.

◆ __setattr__()

def carputils.settings.namespace.SettingsNamespace.__setattr__ (   self,
  attr,
  value 
)

Custom attribute access code providing case-insensitivity and order logging.

◆ __setitem__()

def carputils.settings.namespace.SettingsNamespace.__setitem__ (   self,
  key,
  value 
)

Allow object to be used like dict.

◆ __str__()

def carputils.settings.namespace.SettingsNamespace.__str__ (   self)

◆ get()

def carputils.settings.namespace.SettingsNamespace.get (   self,
  key,
  fallback = None 
)

Get an item without raising errors when missing, like dict().get()

Parameters

key str Key of item to return (case-insensitive) fallback object, optional Value to return when key is missing (default: None)


The documentation for this class was generated from the following file: