comparison query_db.py @ 1:8a33b442ecd9 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/query_tabular commit 81f69ad5f39223059c40501e55ac777d3feca845
author iuc
date Fri, 18 Aug 2017 16:48:09 -0400
parents 3708ff0198b7
children 973f03d82c86
comparison
equal deleted inserted replaced
0:3708ff0198b7 1:8a33b442ecd9
54 except Exception as e: 54 except Exception as e:
55 exit('Error: %s' % (e)) 55 exit('Error: %s' % (e))
56 exit(0) 56 exit(0)
57 57
58 58
59 def run_query(conn, query, outputFile, no_header=False): 59 def run_query(conn, query, outputFile, no_header=False, comment_char='#'):
60 cur = conn.cursor() 60 cur = conn.cursor()
61 results = cur.execute(query) 61 results = cur.execute(query)
62 if not no_header: 62 if not no_header:
63 outputFile.write("#%s\n" % '\t'.join( 63 outputFile.write("%s%s\n" % (comment_char, '\t'.join(
64 [str(col[0]) for col in cur.description])) 64 [str(col[0]) for col in cur.description])))
65 for i, row in enumerate(results): 65 for i, row in enumerate(results):
66 outputFile.write("%s\n" % '\t'.join( 66 outputFile.write("%s\n" % '\t'.join(
67 [str(val) if val is not None else '' for val in row])) 67 [str(val) if val is not None else '' for val in row]))