Mercurial > repos > jjohnson > query_tabular
comparison query_tabular.py @ 7:72c32037fa1e draft
Uploaded
author | jjohnson |
---|---|
date | Sat, 18 Feb 2017 08:35:35 -0500 |
parents | 03842a4f71c6 |
children | ae27dab228b8 |
comparison
equal
deleted
inserted
replaced
6:03842a4f71c6 | 7:72c32037fa1e |
---|---|
215 c = conn.cursor() | 215 c = conn.cursor() |
216 tr = TabularReader(file_path,skip=skip, comment_char=comment_char, col_idx=col_idx, filters=filters) | 216 tr = TabularReader(file_path,skip=skip, comment_char=comment_char, col_idx=col_idx, filters=filters) |
217 for linenum, fields in enumerate(tr): | 217 for linenum, fields in enumerate(tr): |
218 data_lines += 1 | 218 data_lines += 1 |
219 try: | 219 try: |
220 if col_idx: | |
221 fields = [fields[i] for i in col_idx] | |
222 vals = [col_func[i](x) if x else None for i, x in enumerate(fields)] | 220 vals = [col_func[i](x) if x else None for i, x in enumerate(fields)] |
223 c.execute(insert_stmt, vals) | 221 c.execute(insert_stmt, vals) |
224 except Exception, e: | 222 except Exception, e: |
225 print >> sys.stderr, 'Failed at line: %d err: %s' % (linenum, e) | 223 print >> sys.stderr, 'Failed at line: %d err: %s' % (linenum, e) |
226 conn.commit() | 224 conn.commit() |