from seminar import ovvpfile import os def read_all_tables(basedir): tables = {} for fn in os.listdir(basedir): if fn.endswith('.csv'): print "Reading %s ..." % (fn, ) with open(os.path.join(basedir, fn), 'r') as f: o = ovvpfile.parse(f, with_headers=False) tables[fn[:-4]] = o.rows print " %d lines, columns: %s" % (len(o.rows), ' '.join(o.columns), ) return tables def matchrows(tab, key, val): return [r for r in tab if r[key]==val] def onerow(tab, key, val): t = matchrows(tab, key, val) assert(len(t) == 1) return t[0]