代码如下:
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()
def insert_words(self,filename):
file = open(filename)
data = []
for line in file:
tmp = re.split("\s+",line,5)
data.append(tmp)
print(data) # 看看data 里都有啥?
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()
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!