Mercurial > hg > sqlex
diff sqlex/main.py @ 9:834b920ae345 default tip
allow output of headers in csv
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 01 Apr 2017 15:11:34 -0700 |
parents | adf056d67c01 |
children |
line wrap: on
line diff
--- a/sqlex/main.py Sat Apr 01 13:01:57 2017 -0700 +++ b/sqlex/main.py Sat Apr 01 15:11:34 2017 -0700 @@ -42,6 +42,9 @@ help="list columns in `table` and exit") self.add_argument('-o', '--output', help="output to directory (if `table` not given), or filename or stdout by default") + self.add_argument('--header', dest='header', + action='store_true', default=False, + help="export header as first row") self.options = None def parse_args(self, *args, **kw): @@ -102,9 +105,9 @@ if options.output: with open(options.output, 'w') as f: - db.table2csv(options.table, f) + db.table2csv(options.table, f, header=options.header) else: - db.table2csv(options.table, sys.stdout) + db.table2csv(options.table, sys.stdout, header=options.header) sys.stdout.flush() else: # output entire db to CSV files in directory @@ -116,7 +119,7 @@ # export each table path = os.path.join(options.output, '{}.csv'.format(table)) with open(path, 'w') as f: - db.table2csv(table, f) + db.table2csv(table, f, header=options.header) if __name__ == '__main__':