如何在Windows上使用Python将SQLite 2转换为SQLite3?
我正在尝试在Windows上用Python把一个SQLite 2的文件转换成SQLite3。在Linux上,我可以直接把sqlite
的输出通过管道传给sqlite3
,这样很方便:
os.system("sqlite db.sqlite .dump | sqlite3 db3.sqlite")
但是在Windows上,我没有这么方便的方法来转移这个输出。现在我做的是:
sqlite_dump = os.popen('sqlite %s .dump' % sqlite_db).read()
open(sqlite_dump_file, "w").write(sqlite_dump)
os.system("del %s" % sqlite_db)
os.system("sqlite3 -init %s %s" % (sqlite_db,
sqlite_dump_file))
这样做是有效的,但最后我会停留在sqlite3
的提示符下。我试过使用-bail
这个选项,并在SQLite的输出末尾加上`"\n.quit\n"`,但都没有效果。
我该怎么办呢?
1 个回答
3
为什么在Windows上不能像那样使用管道?这样做时出了什么问题?