2017-09-06 23:28:26
import pymysql db = pymysql.connect("localhost","root","hy1102","TESTDB",charset=‘utf8‘) cursor = db.cursor() list=[] with open("E:\\ee.txt","r") as f: for line in f: ls = line.split() for i in range(0,len(ls)): if ls[i] == "NULL": ls[i] = None list.append(ls) f.close() sql ="""insert into shohin VALUES (%s,%s,%s,%s,%s,%s)""" cursor.executemany(sql,list) db.commit() db.close()
注意事项:
原文:http://www.cnblogs.com/TIMHY/p/7487651.html