comparison datafile.py @ 37:3d2306e39700

Move DataFile class to new file for ease of reuse.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 28 Sep 2011 12:29:19 +0930
parents
children 91b476ebc0f2
comparison
equal deleted inserted replaced
36:ff63d71e1383 37:3d2306e39700
1 import exceptions
2 import numpy
3
4 class DataFile(object):
5 def __init__(self, fname):
6 f = file(fname)
7 self.opts = {}
8 for line in f:
9 key, value = line.strip().split(' ', 1)
10 if key == "XDATA":
11 self.freqs = numpy.fromstring(value, sep = ', ')
12 continue
13
14 if key == "YDATA":
15 self.powers = numpy.fromstring(value, sep = ', ')
16 continue
17
18 try:
19 self.opts[key] = int(value)
20 except exceptions.ValueError, e:
21 try:
22 self.opts[key] = float(value)
23 except exceptions.ValueError, e:
24 self.opts[key] = value
25
26 def __getitem__(self, k):
27 return self.opts[k]
28