import pymysql
count = 0
list_dict=[]
def splie_words(words):
index = words.find(" ")
word = words[:index]
intro = words[index:]
return word,intro
db = pymysql.connect(host='localhost',
port=3306,
user='root',
password='123456',
database='dict',
charset='utf8')
curl = db.cursor()
with open("dict.txt") as f:
for e in f.readlines():
count+=1
if count < 19500+1:
word,pro=splie_words(e)
try:
sql = f"insert into words values({count},'{word}','{pro}');"
print(word, pro)
curl.execute(sql)
db.commit()
except Exception as e:
print(e)
db.rollback()
else:
break
curl.close()
db.close()