import json
import sqlite3
con = sqlite3.connect("Test.db")
cur = con.cursor()
# ==https://blog.csdn.net/GuoQiZhang/article/details/91344509 数据库案例.
cur.execute(
"CREATE TABLE IF NOT EXISTS med(id INTEGER PRIMARY KEY,data TEXT)")
cur.execute(
"CREATE TABLE IF NOT EXISTS user(id INTEGER PRIMARY KEY,data TEXT)")
with open('meddata.json', encoding='utf-8') as f: # 调用的高精度腾旭ocr
tmp = f.read()
meddata = json.loads(tmp)
with open('userdata.json', encoding='utf-8') as f: # 调用的高精度腾旭ocr
tmp = f.read()
userdata = json.loads(tmp)
pass
eval(str(meddata[0])) # 我们使用str 和eval来互化.
for dex, i in enumerate(meddata):
# sql = f"INSERT INTO test VALUES ( %s,%s)"
# values = (dex+1, i)
# cur.execute(sql, values)
cur.execute("INSERT INTO med values(?,?)", (dex+1, str(i)))
# cur.execute("INSERT INTO med values(?,?)", (dex+1, "fdsafsdf"))
pass
con.commit() # 必须输入这个才能提交数据.
cur.close()
con.close()
标签:tmp,execute,cur,flask,数据库,json,values,sqlite3
From: https://www.cnblogs.com/zhangbo2008/p/18221219