attrs
Classes
class
AttrDict
(dict)Turn a dict into an object with attributes.
Turn a dict into an object with attributes.
If non-existing attributes are accessed for reading, `None` is returned.
See these links on stackoverflow:
* [1](https://stackoverflow.com/questions/4984647/accessing-dict-keys-like-an-attribute)
* [2](https://stackoverflow.com/questions/16237659/python-how-to-implement-getattr)
especially the remark that
> `__getattr__` is only used for missing attribute lookup
We also need to define the `__missing__` method in case we access the underlying
dict by means of keys, like `xxx["yyy"]` rather then by attribute like `xxx.yyy`.
Attributes
| Name | Type | Description |
|---|---|---|
| __dict__ | — | — |
Methods
__init__(self, args: Any = (), kwargs: Any = {}) → NoneCreate the data structure from incoming data.
Parameters
args: Any= ()kwargs: Any= {}
deepdict(self) → dict[(str, Any)]Functions
function
deepAttrDict(info: Any, preferTuples: bool = False) → AnyTurn a `dict` into an `AttrDict`, recursively.
Turn a `dict` into an `AttrDict`, recursively.
Parameters
----------
info: any
The input dictionary. We assume that it is a data structure built by
`tuple`, `list`, `set`, `frozenset`, `dict` and atomic types such as
`int`, `str`, `bool`.
We assume there are no user defined objects in it, and no generators
and functions.
preferTuples: boolean, optional False
Lists are converted to tuples.
Returns
-------
AttrDict
An `AttrDict` containing the same info as the input dictionary, but where
each value of type `dict` is turned into an `AttrDict`.
Parameters
info: AnypreferTuples: bool= False
function
deepdict(info: Any, ordinary: bool = False) → AnyTurns an `AttrDict` into a `dict`, recursively.
Turns an `AttrDict` into a `dict`, recursively.
Parameters
----------
info: any
The input dictionary. We assume that it is a data structure built by
`tuple`, `list`, `set`, `frozenset`, `dict` and atomic types such as
`int`, `str`, `bool`.
We assume there are no user defined objects in it, and no generators
and functions.
ordinary: boolean, optional False
If True, no frozensets and tuples are constructed, but sets and lists
instead.
Returns
-------
dict
A dictionary containing the same info as the input dictionary, but where
each value of type `AttrDict` is turned into a `dict`.
Parameters
info: Anyordinary: bool= False
function
isIterable(value: Any) → boolWhether a value is a non-string iterable.
Whether a value is a non-string iterable.
!!! note
Strings are iterables.
But for this purpose we regard strings as non-iterable scalars.
Parameters
value: Any