Skip to content

Commit 1ec98c0

Browse files
committed
Correctly interpreting argparse args to fix the --table argument bug when specifying a single file
1 parent cc22887 commit 1ec98c0

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

csvkit/utilities/csvsql.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ def add_arguments(self):
3434
help='A comma separated list of column indices or names to skip type inference. Specified columns will be treated as strings.')
3535

3636
def main(self):
37-
# Ensure we're handling a list, even if it's just one file
38-
if not isinstance(self.args.files, list):
39-
self.args.files = [self.args.files]
40-
else:
41-
if self.args.table_name:
42-
self.argparser.error('The --table argument is only allowed when specifying a single file.')
37+
if len(self.args.files) > 1 and self.args.table_name:
38+
self.argparser.error('The --table argument is only allowed when specifying a single file.')
4339

4440
for f in self.args.files:
4541
if self.args.table_name:
@@ -81,8 +77,7 @@ def main(self):
8177

8278
conn = engine.connect()
8379
trans = conn.begin()
84-
for row in csv_table.to_rows():
85-
conn.execute(insert, [dict(zip(headers, row)), ])
80+
conn.execute(insert, [dict(zip(headers, row)) for row in csv_table.to_rows()])
8681
trans.commit()
8782
conn.close()
8883

0 commit comments

Comments
 (0)