Skip to content

Instantly share code, notes, and snippets.

@codejoust
Created August 25, 2011 15:40
Show Gist options
  • Save codejoust/1170962 to your computer and use it in GitHub Desktop.
Save codejoust/1170962 to your computer and use it in GitHub Desktop.
import_db
import MySQLdb, re
conn = MySQLdb.connect(host = "localhost", user = "testuser", passwd = "testpass", db = "test")
cursor = db.cursor()
datafile = open('taxes.txt')
line = ''
while(line = datafile.readline()):
fields = re.split(r'\|+', line)
cursor.execute("insert into rates (Post_Office,Zip_Code,County,Rate) values('%s','%s','%s','%s');" % (fields[0], fields[1], fields[2], fields[3]))
cursor.close()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment