Created
March 22, 2012 00:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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