How does python read all the sqlite files under a directory
This article mainly explains the "python how to read a directory under all the sqlite files", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "python how to read all the sqlite files under a directory"!
Import sqlite3 as db
Import os
If name== "main":
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) default'', value smallint default 0) ") rootdir ='. / test/' list = os.listdir (rootdir) / / Loop open all sqlite files under the test directory for i in range (0Len (list)): path = os.path.join (rootdir) List [I]) conn_read = db.connect (path) cursor_read = conn_read.cursor () rows = cursor_read.execute (".") / / read data line by line for line in rows: str1 = line [0] str2 = line [1]. . . Cursor_write.execute ("INSERT INTO nav_test VALUES ('{0}','{1}') Format (str1,str2) Thank you for your reading, the above is the content of "how python reads all sqlite files under a directory". After the study of this article, I believe you have a deeper understanding of how python reads all sqlite files under a directory, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!