Skip to content

Instantly share code, notes, and snippets.

@dsedivec
Created March 22, 2012 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsedivec/2154361 to your computer and use it in GitHub Desktop.
Save dsedivec/2154361 to your computer and use it in GitHub Desktop.
Make simple CREATE TABLE from the first line of a tab-delimited data file
# Put this in a file and run it like "python yourscript.py name_of_your_file.csv".
import sys
import csv
csv_file_obj = csv.reader(open(sys.argv[1], "rb"), dialect=csv.excel_tab)
first_row = csv_file_obj.next()
# first_row is now a list of column names, we hope. Feel free to print it out.
print "CREATE TABLE tablename (%s);" % (", ".join("%s TEXT" % (name,) for name in first_row),)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment