Python implements the sqlite3 database read and write statistical data into Excel method example, pythonsqlite3
This example describes how to read and write data from the sqlite3 database in Python and write data into Excel. We will share this with you for your reference. The details are as follows:
src = 'F:\\log\\mha-041log\\rnd-log-dl.huawei.com\\test'# dst = sys.argv[2] dst = 'F:\\log\\mha-041log\\rnd-log-dl.huawei.com\\test\\mha-041log.db'# dst_anylyzed = sys.argv[3] dst_anylyzed = 'F:\\log\\mha-041log\\rnd-log-dl.huawei.com\\test\\mha-041log.xlsx' cx = sqlite3.connect(dst) init_table_title(cx, startcoreapp_table) init_table_title(cx, startwechat_table) init_table_title(cx, coreappjankframe_table) init_table_title(cx, wechatjankframe_table) init_table_title(cx, otherapp_table) os.path.walk(src, visit_zipfile, cx)
Database initialization method:
def init_table_title(c, work_table): global base_index global info_index c.execute('DROP TABLE IF EXISTS ' + work_table); c.execute('CREATE TABLE ' + work_table + ' \ (Product TEXT NOT NULL, \ Version TEXT NOT NULL, \ Imei TEXT NOT NULL, \ Date TEXT NOT NULL, \ Eventid TEXT NOT NULL, \ HappenTime TEXT NOT NULL, \ FIELDNAME TEXT NOT NULL, \ CASENAME TEXT NOT NULL)'); return