comparison query_db.py @ 1:cd2a99849f8b 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:47:57 -0400
parents 6fbd9d25ceef
children fe7be5634ab3
comparison
equal deleted inserted replaced
0:6fbd9d25ceef 1:cd2a99849f8b
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]))