AttyDict

class AttyDict(iterable_or_mapping=None, **kwargs)

A lightweight dictionary with dot access.

attydicts are dictionaries witch allow access to values values through dot notation. The limitation there is that their keys must be strings ( and valid python identifiers ) but sometimes this is what you want when working with json objects unpredictable json or the like. That said, if you have sturctured data you’d of course be much better off using a structured datatype.

Example

initilize a basic attydict:

>>> from collectionish import AttyDict
>>>
>>> the_sea = AttyDict(crabs=10, fish=2)
>>> the_sea
{'crabs': 10, 'fish': 2}

access stuff with dots:

>>> the_sea.crabs += 1
>>> the_sea.crabs
11

nested stuff will also have attr access:

>>> the_sea.update(submarines= {'sandwich': 0, 'actual': 1})
>>> the_sea
{'crabs': 11, 'fish': 2, 'submarines': {'sandwich': 0, 'actual': 1}}
>>> the_sea.submarines.actual
1

we handle name clashes in a similar way to pandas - Reserved names can be set using standard dict access:

>>> the_sea['pop'] = 'corn'
>>> the_sea
{'crabs': 11, 'fish': 2, 'submarines': {'sandwich': 0, 'actual': 1}, 'pop': 'corn'}
>>> the_sea.pop('pop')
'corn'
>>> the_sea
{'crabs': 11, 'fish': 2, 'submarines': {'sandwich': 0, 'actual': 1}}

and as youd expect lists containing dictionaries just work…

>>> the_sea.whales = [{'killer': 1}, {'humpback': 2}, 'mr. whale']
>>> the_sea.whales[1].humpback
2
update([E, ]**F) → None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]