libb.attrdict

class attrdict[source]

Bases: dict

A dictionary subclass that allows attribute-style access.

This is a dictionary that allows access to its keys as attributes (using dot notation) in addition to standard dictionary access methods.

Basic Usage:

>>> import copy
>>> d = attrdict(x=10, y='foo')
>>> d.x
10
>>> d['x']
10
>>> d.y = 'baa'
>>> d['y']
'baa'
>>> g = d.copy()
>>> g.x = 11
>>> d.x
10
>>> d.z = 1
>>> d.z
1
>>> 'x' in d
True
>>> 'w' in d
False
>>> d.get('x')
10
>>> d.get('w')

Deep Copy Behavior:

>>> tricky = [d, g]
>>> tricky2 = copy.copy(tricky)
>>> tricky2[1].x
11
>>> tricky2[1].x = 12
>>> tricky[1].x
12
>>> righty = copy.deepcopy(tricky)
>>> righty[1].x
12
>>> righty[1].x = 13
>>> tricky[1].x
12

Access Methods (handles obj.get('attr'), obj['attr'], and obj.attr):

>>> class A(attrdict):
...     @property
...     def x(self):
...         return 1
>>> a = A()
>>> a['x'] == a.x == a.get('x')
True
>>> a.get('b')
>>> a['b']
Traceback (most recent call last):
    ...
KeyError: 'b'
>>> a.b
Traceback (most recent call last):
    ...
AttributeError: b
get(key, default=None)[source]
update(*args, **kwargs)[source]
copy(**kwargs)[source]