代码如下:
import pymysql
import re
连接数据库,这段代码就先略过了,应该是没有问题
def close(self):
self.cur.close()
self.db.close()
def insert_words(self,filename):
file = open(filename)
data = []
for line in file:
tmp = re.split("\s+",line,5)
data.append(tmp)
try:
sql="insert into Average_leaf_rolling_rate (the_sixth_day," \
"the_nineteenth_day," \
"the_thirty_second_day," \
"the_forty_fourth_day," \
"the_fifty_fifth_day," \
"the_sixty_ninth_day) values (%s,%s,%s,%s,%s,%s);"
self.cur.executemany(sql,data)
self.db.commit()
except:
self.db.rollback()
if name == 'main':
aver = Aver()
aver.insert_words("111.txt")
aver.close()