EndfVariable

class endf_parserpy.EndfVariable(endf_path, endf_dict, value=None)[source]

Class to keep a reference to a location in a (nested) dictionary.

An instance of this class is connected to a specific key in a (nested) dictionary and its associated object. The instance attribute .value allows to set or retrieve the object linked to the specific key in the dictionary. The purpose of this class is to provide a mechanism to pass around objects that can be treated like variables but are always in sync with the data in a given dictionary.

Create and associate EndfVariable with location in dictionary.

Parameters:
  • endf_path (EndfPath) – An EndfPath instance (or an object that is accepted by the EndfPath constructor) establishing the link to a specific location in a nested dict_like object.

  • endf_dict (dict) – A (nested) dict_like object that contains a key referenced by the endf_path argument.

property name

Name of the associated key in the nested dictionary.

Example

>>> v = EndfVariable('a/b', {'a': {'b': 5}})
>>> assert v.name == 'b'
property path

Path of associated key in nested dictionary.

Example

>>> d = {'a': {'b': 5}}
>>> v = EndfVariable('a/b', d)
>>> assert v.path == EndfPath('a/b')
property value

Value of the associated key in the nested dictionary.

The value of this propert can also be modified, which accordingly modifies the value stored under the associated key in the nested dict_like object.

Example

>>> d = {'a': {'b': 5}}
>>> v = EndfVariable('a/b', d)
>>> assert v.value == d['a']['b']
>>> v.value = 10
>>> assert d['a']['b'] == 10