summaryrefslogtreecommitdiff
path: root/common/__init__.py
blob: 41f1329a3d076553d6d57e2e0d2b24a8aa442a2e (plain)
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
import math

def load_data_from_file (path: str, mask_noent = True):
	try:
		with open(path) as f:
			return load_data(f.readline)
	except FileNotFoundError as e:
		if not mask_noent:
			raise e

	return dict()

def load_data (read_f):
	ret = dict()

	while True:
		l = read_f()
		if not l:
			break

		tpl = l.strip().split()
		v = float(tpl[1])
		if math.isfinite(v):
			ret[tpl[0]] = v

	return ret