EndfDict
- class endf_parserpy.EndfDict(obj=None, array_type='dict')[source]
EndfDict class extends
dictwithEndfPathfunctionality.The
EndfDictclass behaves like alistbut offers in addition enhanced indexing capabilities. This class is derived from theEndfObjectclass and inherits its methods.Constructor for the
EndfDictclass.- Parameters:
- exists(path)
Check whether object exists under path.
- property path
Get the
EndfPathassociated with thisEndfDict.If this
EndfDictwas retrieved from anotherEndfDict, thepathattribute contains the associated location in the nested dictionary.Example
>>> testdict = {'a': {'b': 'c'}} >>> viewdict = EndfDict(testdict) >>> viewdict2 = viewdict['a/b'] >>> assert viewdict2.path == EndfPath('a/b')
- property root
Get the
EndfDictinstance associated with the root dictionary.Any
dict-like object retrieved from anEndfDict(termed the rootEndfDict) is automatically enwrapped in anEndfDictinstances before being returned to the user. Therootattribute of the returnedEndfDictinstances holds a reference to the rootEndfDictobject.Example
>>> testdict = {'a': {'b': {'c': 'd'}}} >>> viewdict = EndfDict(testdict) >>> assert id(viewdict) == id(viewdict.root) >>> viewdict2 = testdict['a/b'] >>> assert id(viewdict2.root) == id(viewdict)
- unwrap(recursive=False)
Returns the underlying base object.
The
EndfObjectclass can be regarded as an interface wrapping around an underlyingdict- orlist-like object. This function permits the retrieval of the underlying object.- Parameters:
recursive (bool) – If
True, allEndfObjectobjects present in the underlying object are recursively converted to their base type, i.e. eitherdictorlist.- Returns:
The underlying base object.
- Return type:
Note
The use of
recursive=Trueis only necessary if the user has stored anEndfObjectobject anywhere in the underlying base object. In contrast, if an attempt is made to store anEndfObjectobject in anotherEndfObjectobject, the former object is (non-recursively) unwrapped (withunwrap()) before being stored. Therefore, as long as the underlying base object is only accessed via anEndfDictinstance, there should never be anEndfObjectobject in the underlying base object.Example
>>> testdict = {'a': 1, 'b': 2} >>> viewdict = EndfDict(testdict) >>> assert id(testdict) != id(viewdict) >>> retdict = viewdict.unwrap() >>> assert id(testdict) == id(retdict)