Mercurial > repos > jjohnson > query_tabular
comparison query_tabular.py @ 3:125fc5d123b3
Remove \r\n chars from input when loading db table
author | Jim Johnson <jj@umn.edu> |
---|---|
date | Wed, 04 Nov 2015 15:45:19 -0600 |
parents | ffa5e34a55c1 |
children |
comparison
equal
deleted
inserted
replaced
2:ffa5e34a55c1 | 3:125fc5d123b3 |
---|---|
92 for linenum,line in enumerate(fh): | 92 for linenum,line in enumerate(fh): |
93 if linenum < skip or line.startswith(comment_char): | 93 if linenum < skip or line.startswith(comment_char): |
94 continue | 94 continue |
95 data_lines += 1 | 95 data_lines += 1 |
96 try: | 96 try: |
97 fields = line.split('\t') | 97 fields = line.rstrip('\r\n').split('\t') |
98 vals = [col_func[i](x) if x else None for i,x in enumerate(fields)] | 98 vals = [col_func[i](x) if x else None for i,x in enumerate(fields)] |
99 c.execute(insert_stmt,vals) | 99 c.execute(insert_stmt,vals) |
100 except Exception, e: | 100 except Exception, e: |
101 print >> sys.stderr, 'Failed at line: %d err: %s' % (linenum,e) | 101 print >> sys.stderr, 'Failed at line: %d err: %s' % (linenum,e) |
102 conn.commit() | 102 conn.commit() |