ATLAS Offline Software
Loading...
Searching...
No Matches
python.Utilities.ldict Class Reference
Inheritance diagram for python.Utilities.ldict:
Collaboration diagram for python.Utilities.ldict:

Public Member Functions

 __init__ (self, **args)
 __setitem__ (self, k, v)
 update (self, **args)
 clone (self, **args)

Detailed Description

A dictionnary which items can not be modified once set.

Also implements 2 additional features :
 - a clone method to conveniently create a new version with only some items changed
 - all items are also attributes (i.e. d['a'] can be accessed by d.a : this is mostly for easier interactive inspection)

Definition at line 139 of file Utilities.py.

Constructor & Destructor Documentation

◆ __init__()

python.Utilities.ldict.__init__ ( self,
** args )

Definition at line 146 of file Utilities.py.

146 def __init__(self, **args):
147 super().__init__(**args)
148 # make key aivailable as attribute
149 for k,v in args.items():
150 super().__setattr__(k,v)
151

Member Function Documentation

◆ __setitem__()

python.Utilities.ldict.__setitem__ ( self,
k,
v )

Definition at line 152 of file Utilities.py.

152 def __setitem__(self, k, v):
153 if k in self:
154 if v!=self[k]:
155 raise KeyError(f"Can't override self[{k}] == {self[k]} with new value {v}")
156 else:
157 super().__setitem__(k,v)
158 super().__setattr__(k,v)
159

◆ clone()

python.Utilities.ldict.clone ( self,
** args )

Definition at line 164 of file Utilities.py.

164 def clone(self,**args):
165 from copy import deepcopy
166 o = deepcopy(self)
167 for k,v in args.items():
168 # bypass the protection to update the user given items
169 dict.__setitem__(o,k,v)
170 dict.__setattr__(o,k,v)
171 return o
172

◆ update()

python.Utilities.ldict.update ( self,
** args )

Definition at line 160 of file Utilities.py.

160 def update(self, **args): # we need to redefine it
161 for k,v in args.items():
162 self[k]=v
163

The documentation for this class was generated from the following file: