时间:2021-07-01 10:21:17 帮助过:50人阅读
if os.path.exists("./output/test.db"):
os.remove("./output/test.db")
conn_write = db.connect(‘./output/test.db‘)
cursor_write = conn_write.cursor()
cursor_write.execute("CREATE TABLE nav_test ( test_id varchar(128) default ‘‘, value smallint default 0);")
rootdir = ‘./test/‘
list = os.listdir(rootdir)
//循环打开test 目录下面的所有sqlite文件
for i in range(0,len(list)):
path = os.path.join(rootdir,list[i])
conn_read = db.connect(path)
cursor_read = conn_read.cursor()
rows = cursor_read.execute("......")
//逐行读取数据
for line in rows:
str1 = line[0]
str2 = line[1]
......
.....
.....
cursor_write.execute("INSERT INTO nav_test VALUES (‘{0}‘, ‘{1}‘); ".format(str1,str2))
python读取一个目录下面的所有sqlite文件 然后写到同一个数据库文件test.db中
标签:table str1 main os.path line format 读取数据 var write