cfdm.Configuration


class cfdm.Configuration[source]

Bases: dict

Dictionary-like container for the global constants.

The container has context manager support.

Initialisation is as for a dict, and nearly all of the dict methods are available with the same behaviours (clear, fromkeys, get, items, keys, pop, popitem, setdefault, update, values):

>>> c = cfdm.Configuration(atol=0.1, rtol=0.2, log_level='INFO')
>>> c
<Configuration: {'atol': 0.1, 'rtol': 0.2, 'log_level': 'INFO'}>
>>> print(c)
{'atol': 0.1, 'rtol': 0.2, 'log_level': 'INFO'}
>>> c.pop('atol')
0.1
>>> c
<Configuration: {'rtol': 0.2, 'log_level': 'INFO'}>
>>> c.clear()
>>> c
<Configuration: {}>

The copy method return a deep copy, rather than a shallow one.

Context manager

The Configuration instance can be used as a context manager that upon exit executes the function defined by the _func attribute, with the class itself as input kwargs parameters. For example, the Configuration instance c would execute c._func(**c) upon exit.

New in version (cfdm): 1.8.8.0

Store components.

Copying

Methods

copy

Return a deep copy.

Dictionary functionality

Methods

clear

fromkeys

Create a new dictionary with keys from iterable and values set to value.

get

Return the value for key if key is in the dictionary, else default.

items

keys

pop

If key is not found, d is returned if given, otherwise KeyError is raised

popitem

Remove and return a (key, value) pair as a 2-tuple.

setdefault

Insert key with a value of default if key is not in the dictionary.

update

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]

values

Special

Methods

__enter__

Enter the runtime context.

__exit__

Exit the runtime context.

__repr__

Called by the repr built-in function.