forked from jmlingeman/Network-Inference-Workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadConfig.py
37 lines (31 loc) · 1.06 KB
/
ReadConfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def ReadConfig(settings={},config_file=None):
if config_file != None:
file_loc = config_file
else:
file_loc = "./config.cfg"
file = open(file_loc, 'r')
for line in file:
# Each line should have the format of algname.paramname = value
if len(line) > 1 and line.strip()[0] != '#':
algname = line.split(".")[0].lower()
paramname = line[line.find('.')+1:line.find('=')].strip().lower()
value = line.split('=')[1].strip()
value = value.split(',')
for i in xrange(len(value)):
value[i] = value[i].strip()
if value[i].lower() == "none":
value[i] = None
elif value[i].isdigit():
value[i] = int(value[i])
else:
try:
value[i] = float(value[i])
except:
pass
if len(value) == 1:
value = value[0]
if algname not in settings.keys():
settings[algname] = {}
settings[algname][paramname] = value
#print settings
return settings