cf.Configuration


class cf.Configuration(*args, **kwargs)[source]

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 = cf.Configuration(atol=0.1, rtol=0.2, log_level='INFO')
>>> c
<CF 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
<CF Configuration: {'rtol': 0.2, 'log_level': 'INFO'}>
>>> c.clear()
>>> c
<CF 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.

Added in version (cfdm): 1.8.8.0

Must override this method in subclasses.

Copying

Methods

copy

Return a deep copy.

Dictionary functionality

Methods

clear

D.clear() -> None.

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

D.items() -> a set-like object providing a view on D's items

keys

D.keys() -> a set-like object providing a view on D's keys

pop

D.pop(k[,d]) -> v, remove specified key and return the corresponding value.

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

D.update([E, ]**F) -> None.

values

D.values() -> an object providing a view on D's values

Special

Methods

__enter__

Enter the runtime context.

__exit__

Exit the runtime context.

__repr__

Called by the repr built-in function.