Permalink
Browse files

Correctly interpreting argparse args to fix the --table argument bug …

…when specifying a single file
  • Loading branch information...
crosenth committed Dec 7, 2012
1 parent cc22887 commit 1ec98c0fcf85a28f3620a62850c3d03be92b5989
Showing with 3 additions and 8 deletions.
  1. +3 −8 csvkit/utilities/csvsql.py
View
@@ -34,12 +34,8 @@ def add_arguments(self):
help='A comma separated list of column indices or names to skip type inference. Specified columns will be treated as strings.')
def main(self):
- # Ensure we're handling a list, even if it's just one file
- if not isinstance(self.args.files, list):
- self.args.files = [self.args.files]
- else:
- if self.args.table_name:
- self.argparser.error('The --table argument is only allowed when specifying a single file.')
+ if len(self.args.files) > 1 and self.args.table_name:
+ self.argparser.error('The --table argument is only allowed when specifying a single file.')
for f in self.args.files:
if self.args.table_name:
@@ -81,8 +77,7 @@ def main(self):
conn = engine.connect()
trans = conn.begin()
- for row in csv_table.to_rows():
- conn.execute(insert, [dict(zip(headers, row)), ])
+ conn.execute(insert, [dict(zip(headers, row)) for row in csv_table.to_rows()])
trans.commit()
conn.close()

0 comments on commit 1ec98c0

Please sign in to comment.