template_class.py
Go to the documentation of this file.
1 # Author: Moritz Reichert
2 # Date : 26.09.2024
3 import numpy as np
4 
5 
6 class template(object):
7  """
8  Class to read a WinNet template file.
9  """
10 
11  def __init__(self, path):
12  """
13  Initialize the template class.
14  """
15  self.path = path
16 
17 
18  def read_data(self):
19  """
20  Read the data from the template file and store it in a dictionary.
21  """
22  # Create an empty dictionary to store the entries
23  self.__entries = {}
24 
25  # Read the data from the file
26  with open(self.path, 'r') as f:
27  self.data = f.readlines()
28  for line in self.data:
29  if line.strip().startswith('#'):
30  continue
31 
32  if line.strip() =="":
33  continue
34 
35  key = line.split("=")[0].strip()
36  value = line.split("=")[1].strip().replace('"', '')
37  self.__entries[key] = value
38 
39  @property
40  def entries(self):
41  """
42  Get the entries of the template file.
43  """
44  if not hasattr(self, '__entries'):
45  self.read_data()
46  return self.__entries
47 
48 
49  def __getitem__(self, key):
50  """
51  Get the value of a specific key.
52  """
53  if not hasattr(self, 'entries'):
54  self.read_data()
55  return self.entries[key]
56 
57 
58 if __name__ == '__main__':
59  # Example:
60  path = '../../runs/test'
61  t = template(path)
62  print(t["isotopes_file"])
bin.class_files.template_class.template.__init__
def __init__(self, path)
Definition: template_class.py:11
bin.class_files.template_class.template.path
path
Definition: template_class.py:15
bin.class_files.template_class.template
Definition: template_class.py:6
bin.class_files.template_class.template.__entries
__entries
Definition: template_class.py:23
bin.class_files.template_class.template.data
data
Definition: template_class.py:27
bin.class_files.template_class.template.entries
def entries(self)
Definition: template_class.py:40
bin.class_files.template_class.template.read_data
def read_data(self)
Definition: template_class.py:18
bin.class_files.template_class.template.__getitem__
def __getitem__(self, key)
Definition: template_class.py:49