Reduced invective

BBands bbands at gmail.com
Tue Dec 19 10:49:34 EST 2006


My fat-fingered alter ego typed
    delete from iv where date > '2006-01-01';
instead of
    delete from iv where date > '2006-12-01';
leaving me with 50 tables to reload. :(

estimated time to fix > several hours
estimated invective dispensed during fix = classified

Python to the rescue!

import os
import MySQLdb

files = os.listdir("d:\\hedge\\old data\\")

conn = MySQLdb.connect(host = 'host',
                       user = 'user',
                       passwd = 'pass',
                       db = 'db')
curs = conn.cursor()

for line in files:
    if line[-4:] == "2006":
        SQL = "LOAD DATA "
        SQL += "INFILE 'd:/hedge/old data/" + line
        SQL += "' INTO TABLE iv "
        SQL += "FIELDS TERMINATED BY ',' "
        SQL += "(symbol, date, iv, pv, cv);"
        curs.execute(SQL)

time to execute = 5 mins
invective dispensed while executing = 0

A hearty thank you and Happy Holidays to all in the Python community.

     jab




More information about the Python-list mailing list