changeset 40:37378374b218

implement
author Jeff Hammel <k0scist@gmail.com>
date Fri, 21 Nov 2014 13:35:47 -0800
parents 3c3b793fcffc
children dee0a650bd5a
files numerics/fields.py
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/numerics/fields.py	Fri Nov 21 13:16:39 2014 -0800
+++ b/numerics/fields.py	Fri Nov 21 13:35:47 2014 -0800
@@ -23,5 +23,24 @@
             with open(f) as _f:
                 return self.parse(_f)
 
-        
+        reader = csv.reader(f)
+        retval = []
+        for row in reader:
+
+            # ensure row length is correct
+            if len(row) != len(self.fields):
+                raise Exception("{} | Unrecognized summary row: {}".format(f.name, row))
+
+            # make a data object
+            values = dict(zip(self.names(), row))
 
+            # convert
+            try:
+                for name, _type in self.fields:
+                    values[name] = _type(values[name])
+            except Exception as e:
+                raise Exception("{} | Unable to convert row: {}".format(f.name, e))
+
+            retval.append(values)
+        return values
+