# Script to add links from a comma deliminated file to a MySQL database
# 9/16/05
import MySQLdb
conn=MySQLdb.connect( host="www.freesql.org",
user="edhotchkiss",
port=3306,
passwd="test1",
db="links")
cursor = conn.cursor()
stmt = "DROP TABLE IF EXISTS links"
cursor.execute(stmt)
stmt = """CREATE TABLE links (
ID INT NOT NULL,
Name TEXT,
URL LONGTEXT,
Category LONGTEXT,
primary key (ID)
)"""
cursor.execute(stmt)
arr=[]
inp = open ("sites1.txt","r")
#read line into array
for line in inp.readlines():
links = map(str, line.split(","))
arr.append(links)
cursor.execute
("""
INSERT INTO links (Name, URL, category)
VALUES (%s, %s, %s) % tuple(links[0:3])
""")
cursor.close()
conn.close()
--
edward hotchkiss
-- http://mail.python.org/mailman/listinfo/python-list