nnsa.parameters package
Submodules
nnsa.parameters.parameters module
Utils related to classes.
Classes:
|
Base class for a class that has parameters. |
Class for collecting parameters. |
- class nnsa.parameters.parameters.ClassWithParameters(**kwargs)[source]
Bases:
objectBase class for a class that has parameters.
- Parameters:
**kwargs (optional) – optional keyword arguments for overruling default parameters. For a description of the possible parameters, see the default_parameters() method.
Methods:
Return the default parameters as a dictionary.
- class nnsa.parameters.parameters.Parameters[source]
Bases:
dictClass for collecting parameters.
Inherits from dict, so functionality is mostly identical to dict. Customized/added methods of Parameters are:
__repr__: returns a more readable representation of the set. add: mimics the update method of dict to add new entries. update: only accepts existing keys.
Examples
>>> d = {'a': 1, 'b': {'c': {'d': 1}, 'e': 1}}
>>> p = Parameters(**d) >>> print(p) Parameters object with: a: 1 b: {'c': {'d': 1}, 'e': 1}
>>> p.update({'b': {'e': 2}}) >>> print(p) Parameters object with: a: 1 b: {'c': {'d': 1}, 'e': 2}
>>> p.update({'c': 2}) Traceback (most recent call last): ... KeyError: "'c' not in collection with keys ['a', 'b']."
>>> p['c'] = 3
>>> p.add({'x': 3, 'y': {'z': 3}})
>>> dict(p) {'a': 1, 'b': {'c': {'d': 1}, 'e': 2}, 'c': 3, 'x': 3, 'y': {'z': 3}}
Methods:
add([other])Add or update keys, value pairs in the Parameters set (in place).
update([other])Update key, value pairs in the Parameter set, accepting only existing keys.
- add(other=None, **kwargs)[source]
Add or update keys, value pairs in the Parameters set (in place).
- Parameters:
other (dict or iterable, optional) – dictionary or iterable of key, value pairs to add to the Parameters set.
**kwargs (optional) – keyword arguments to add (in which the keyword is the key).
- update(other=None, **kwargs)[source]
Update key, value pairs in the Parameter set, accepting only existing keys.
Updates nested dictionaries/Parameters objects up to arbitrary levels. In the deeper levels, non-existing keys are accepted if they are from an ordinary dict. In contrast, updating a non-existent key in a deeper Parameters object will raise an error.
- Parameters:
other (dict or iterable, optional) – dictionary or iterable of key, value pairs with which to update.
**kwargs (optional) – keyword arguments with which to update (in which the keyword is the key).
- Raises:
KeyError – if key to update not in Parameter set.
Module contents
Module for Parameters class.