pydfnWorks
python wrapper for dfnWorks
dfntools.py
Go to the documentation of this file.
1 """ Tools for dfnworks data """
2 
3 
4 class Frozen(object):
5  """
6  Prevents adding new attributes to classes once _freeze() is called on the class.
7 
8  Parameters
9  ----------
10  None
11 
12  Returns
13  -------
14  None
15 
16  Notes
17  -----
18  None
19 
20  """
21  frozen = False
22 
23  def __setattr__(self, key, value):
24  """
25  Set attribute to a value.
26  Args:
27  key (string): the key of the attribute being set.
28  value : the value of the attribute being set.
29  """
30  if not self.frozenfrozenfrozen or hasattr(self, key):
31  object.__setattr__(self, key, value)
32  else:
33  raise AttributeError(
34  str(key) + ' is not a valid attribute for ' +
35  self._class__.__name__)
36 
37  def _freeze(self):
38  """
39  Prevents adding new attributes to a class.
40  """
41  self.frozenfrozenfrozen = True
42 
43  def _unfreeze(self):
44  """
45  Allows adding new attributes to classes.
46  """
47  self.frozenfrozenfrozen = False
def __setattr__(self, key, value)
Definition: dfntools.py:23